Reusing a group of regular expressions in a string

I am trying to reuse a regex bunch.

What do I have:

Other Stuff 
Other Stuff
Anker: 'Result1' 'Result2' 'Result3' 'Result4' 'ResultN'
Other Stuff
Other Stuff

      

What I want:

$aVariable = [Result1, Result2, Result3, Result4, ResultN];

      

What I have tried:

Anker:(?: '(.*?)')+

      

(And believe me, many, many other regular expressions, but I don't understand.)

What's the correct way to get multiple items on one line?

Thanks in advance!

+3


source to share


1 answer


Try the below \G

binding based regex.

$re = "/(?:^Anker:|\\G(?!^))\\h*'([^']*)'/m";
$str = "Other Stuff \nOther Stuff\nAnker: 'Result1' 'Result2' 'Result3' 'Result4' 'ResultN'\nOther Stuff\nOther Stuff";

preg_match_all($re, $str, $matches);
print_r($matches[1]);

      



DEMO

+2


source







All Articles