Monkey D Naruto
Monkey D Naruto

Reputation: 176

Capture all repeated groups

I want to capture all string inside the curly braces in this string:

_{test_1} != '' || _{_str_test_2} != 'Yes' && _{_test_str_3} == 'Yes'

This is my regex pattern:

(?:.*(?:_{(.+)+})+.*)+

But the problem is, it only captures the last match.

How can I capture all of the matches ?

Thanks!

Upvotes: 0

Views: 46

Answers (1)

mith
mith

Reputation: 1700

Try this

$str = "_{test_1} != '' || _{_str_test_2} != 'Yes' && _{_test_str_3} == 'Yes'";
$pattern = '#{(.*?)}#s';

preg_match_all($pattern,$str,$matches);

print_r($matches);

Upvotes: 1

Related Questions