Questions tagged [preg-match-all]

A PHP function that performs a global regular expression match using PCRE patterns.

A PHP function that performs a global regular expression match using PCRE patterns.

int preg_match_all ( 
     string $pattern , 
     string $subject 
     [, array &$matches 
     [, int $flags = PREG_PATTERN_ORDER 
     [, int $offset = 0 ]]] 
)

preg_match_all() in the PHP Manual

1934 questions
8
votes
5 answers

Regexp for german phone number format

I try to get phone numbers from string in german format. But I don't get it to full run. The input text is a full HTML-Page with lots of content, not only the numbers. Possible Formats: (06442) 3933023 (02852) 5996-0 (042) 1818 87 9919 …
Mann87
  • 314
  • 1
  • 4
  • 14
8
votes
2 answers

PHP: split string on comma, but NOT when between braces or quotes?

In PHP I have the following string : $str = "AAA, BBB, (CCC,DDD), 'EEE', 'FFF,GGG', ('HHH','III'), (('JJJ','KKK'), LLL, (MMM,NNN)) , OOO"; I need to split this string into the following…
Dylan
  • 9,129
  • 20
  • 96
  • 153
8
votes
2 answers

preg_match_all into simple array

I have preg_match_all function: preg_match_all('#

(.*?)

#is', $source, $output, PREG_SET_ORDER); It's working as intended, BUT the problem is, it preg_matches all items twice and into a huge multi dimensional array like this for example…
DadaB
  • 762
  • 4
  • 12
  • 29
8
votes
2 answers

PHP/REGEX: Get a string within parentheses

This is a really simple problem, but I couldn't find a solution anywhere. I'm try to use preg_match or preg_match_all to obtain a string from within parentheses, but without the parentheses. So far, my expression looks like this: \([A-Za-z0-9…
Macks
  • 1,696
  • 5
  • 23
  • 38
7
votes
2 answers

Regex - get elements to render if statement

I'm designing a script and trying to get to the if construct without eval in php. Still incomplete but blasting through, it's to do a templating engine, the "if" part of the engine. no Assignment operators allowed, but I need to test values without…
Luc Laverdure
  • 1,398
  • 2
  • 19
  • 36
7
votes
2 answers

Count length of images in a string

I am trying to get length of images in a string. My string $page=""; From the string above ,I want to get the output "4 images". I tried preg_match_all() and count() function, but it always returns "1…
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
7
votes
2 answers

preg_match_all with callback?

I'm interested in replace numeric matches in real time and manipulate them to hexadecimal. I was wonder if it's possible without using foreach loop. so iow... every thing in between : = {numeric value} ; will be manupulated to : = {hexadecimal…
iprophesy
  • 175
  • 3
  • 9
7
votes
3 answers

php get the number from a string

I have this string @[123:peterwateber] hello there 095032sdfsdf! @[589:zzzz] I want to get 123 and 589 how do you that using regular expression or something in PHP? Note: peterwateber and zzzz are just examples. any random string should be…
Peter Wateber
  • 3,824
  • 4
  • 21
  • 26
6
votes
4 answers

Regex pattern using w.* not matching text starting with foreign characters such as Ä

I have the following regex that I have been using successfully: preg_match_all('/(\d+)\n(\w.*)\n(\d{3}\.\d{3}\.\d{2})\n(\d.*)\n(\d.*)/', $text, $matches) However I have just found that if the text that the (\w.*) part matches starts with a foreign…
SammyBlackBaron
  • 847
  • 3
  • 13
  • 31
6
votes
1 answer

PHP Regex Expression Involving Japanese

My goal is to filter through a Microsoft Word Document (.docx) grabbing all Japanese kanji and kana. The current code I am working with is the following: preg_match_all('~[\x{4e00}-\x{9faf}]([\x{3040}-\x{309f}]) \= ([a-z]) \=+~u', $data,…
Bryse Meijer
  • 197
  • 2
  • 11
6
votes
1 answer

PHP - preg_match_all - a little advenced

I need to find specific part of text in string. That text need to have: 12 characters (letters and numbers only) whole string must contains at least 3 digits 3*4 characters with spaces (ex. K9X6 6GM6 LM11) every block from example above must…
breq
  • 24,412
  • 26
  • 65
  • 106
6
votes
2 answers

preg_match_all - regex to find full urls in string

I have spent over 4 hours trying to find a regex patter to my php code without luck. I have a string with html code. It has lot of urls formats…
5
votes
1 answer

PHP: unexpected PREG_BACKTRACK_LIMIT_ERROR

function recursiveSplit($string, $layer) { $err = preg_match_all("/\{(([^{}]*|(?R))*)\}/",$string,$matches); echo "Elementi trovati: $err
"; if($err == FALSE) echo "preg_match_all ERROR
"; // iterate thru matches and continue…
Marco
  • 319
  • 1
  • 5
  • 15
5
votes
6 answers

How preg_match_all() processes strings?

I'm still learning a lot about PHP and string alteration is something that is of interest to me. I've used preg_match before for things like validating an email address or just searching for inquiries. I just came from this post What's wrong in my…
Brodie
  • 8,399
  • 8
  • 35
  • 55
5
votes
2 answers

Finding urls from text string via php and regex?

I know the question title looks very repetitive. But some of the solution i did not find here. I need to find urls form text string: $pattern = '`.*?((http|https)://[\w#$&+,\/:;=?@.-]+)[^\w#$&+,\/:;=?@.-]*?`i'; if…
Sisir
  • 2,668
  • 6
  • 47
  • 82