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
4
votes
4 answers

Regex that extracts text between tags, but not the tags

I want to write a regex which extract the content that is between two tags in a string but not the tags. IE I have the following <title>My work

This is my work.

Learning regex.

The regex…
Nicolaesse
  • 2,554
  • 12
  • 46
  • 71
4
votes
3 answers

Regex with attributes

I would like to parse this kind of code : {articles mode="extrait" nb="3"} I am using this regex : @\{(articles)(?:(?:\s|\ )*(?:(\w+)="(\w+)"))*\}@ But it doesn't work, when I do a preg_match_all, here is the result of a print_r with the…
Pascal Messana
  • 277
  • 4
  • 12
4
votes
1 answer

preg_match for certain part of the comments

i want to find certain part of the comments. following are some examples /* * @todo name another-name taskID */ /* @todo name another-name taskID */ currently im using following regular expression '/\*[[:space:]]*(?=@todo(.*))/i' this returns…
Basit
  • 16,316
  • 31
  • 93
  • 154
4
votes
2 answers

Preg_match_all not stopping where it should be

Update Yahoo error Ok, so I got it all working, but the preg_match_all wont work towards Yahoo. If you take a look at: http://se.search.yahoo.com/search?p=random&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t then you can see that in their html, they have…
Vanchi
  • 148
  • 1
  • 8
4
votes
1 answer

PHP: Find statement in statement with regular expression

currently i have the following situation: I'm trying to "parse" a text, looking for placeholders (their notation is "{...}") and later on, i will replace them with the actual text. I thought about regular expressions $foo = "Hello World {foo{bar}}…
Timetrick
  • 186
  • 1
  • 9
4
votes
2 answers

PHP - preg_match_all not searching the full string?

I'm using preg_match_all to search through a file that I'm reading in. The file contains many lines of the following format and I'm extracting the numbers between the tags; 1 2 3 4 5…
user1107685
  • 441
  • 1
  • 4
  • 13
4
votes
4 answers

Why preg_match_all forces me to provide the 3rd optional parameter?

I'm counting the number of some special characters (like euro symbol) in $text, using preg_match_all and this regular expression: preg_match_all('/[\[|\]|€\{|}|\\|\^|\||~]/u', $text); For some strange reason PHP asks me for a third parameter. But…
gremo
  • 47,186
  • 75
  • 257
  • 421
4
votes
1 answer

Using REGEX with escaped quotes inside quotes

I have a PHP preg_match_all and REGEX question. I have the following code: Blahhhh"'; preg_match_all('/(.*?)\s*=\s*(\'|"|&#?\w+;)(.*?)\2/s', trim($string),…
cmfolio
  • 3,413
  • 1
  • 16
  • 13
3
votes
3 answers

Grab text between specific tags in PHP file

Sorry if this question has already been answered elsewhere. I looked through stack overflow and couldn't find exactly what I was looking for. I need to know how to scan multiple php files in a single directory (test/ for example), and extract text…
klye_g
  • 1,242
  • 6
  • 31
  • 54
3
votes
4 answers

extract greater than 4 digit numbers from a string php regular expression

preg_match_all('/(\d{4})/', $text, $matches); Using above function we can extract exact 4 digit numbers from a given string. How can extract the numbers that contains greater than 4 digits using regular expression.. Is there any way to specify the…
Muthu Krishnan
  • 1,664
  • 2
  • 10
  • 15
3
votes
4 answers

preg_match doesn't capture the content

what is wrong with my preg_match ? preg_match('numVar("XYZ-(.*)");',$var,$results); I want to get all the CONTENT from here: numVar("XYZ-CONTENT"); Thank you for any help!
user864720
3
votes
4 answers

Regular Expression (preg_match)

This is the not working code:
Helena
  • 115
  • 1
  • 3
  • 12
3
votes
2 answers

Iterating over matches from preg_match_all

I am trying to figure out the mechanics of this plugin in WordPress. I have a preg_match_all function that looks like this: preg_match_all('/(?<=\\[\\[).+?(?=\\]\\])/', $content, $matches, PREG_PATTERN_ORDER); $numMatches = count($matches[0]); for…
AlxVallejo
  • 3,066
  • 6
  • 50
  • 74
3
votes
3 answers

End-line anchor, $, not behaving as expected

I have this code to process a config file in Windows:
MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
3
votes
1 answer

Regular expression to detect line that starts with an asterisk

The code below fails to detect a single instance of the occurance. =O Whats wrong? =\ How do I detect the following lines (which begin with a newline) that begin with an asterisk ? I'm at a loss. This isn't behaving as I expected. $text ="Nothing…
Timothy Martens
  • 678
  • 4
  • 17