0

我怎样才能得到括号中所有单词的数组?

$text = 'lorem (try) (table) lorem (try1)'; 
preg_match('/\((.+)\)/', $text, $coincidencias);
echo $coincidencias;

谢谢。

4

1 回答 1

0

在你的正则表达式中使用preg_match_all()而不是preg_match()和使用 nongreedy 修饰符?只匹配到下一次关闭)

$text = 'lorem (try) (table) lorem (try1)';
preg_match_all('/\((.+?)\)/', $text, $coincidencias);
var_dump( $coincidencias);
于 2013-10-09T11:51:37.840 回答