捕获所有重复的组

Capture all repeated groups

我想捕获此字符串中花括号内的所有字符串:

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

这是我的正则表达式模式:

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

但问题是,它只捕获最后一场比赛。

如何捕获所有匹配项?

谢谢!

试试这个

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

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

print_r($matches);