[^()]+|(?R))*\)/",$string,$matches)) { echo ""; print_r($matches); echo " "; } 上面是网上找到的嵌套正则写法,把string改成: $string ="> 跳转到主内容
趣航编程网 - 趣学编程,启航技术之路!

嵌套正则写法,该怎么解决

嵌套正则写法 PHP code
$string = "some text (a(b(c)d)e) more text"; if(preg_match("/\((?>[^()]+|(?R))*\)/",$string,$matches)) { echo "
"; print_r($matches); echo "
"; } 上面是网上找到的嵌套正则写法,把string改成: $string = 'some text cde more text'; 改成这样后,正则规则我换不过来了,亲大虾帮忙改一下。 最好能做到 个数不确定的嵌套匹配 ------解决方案-------------------- PHP code
abcde more text';preg_match("/(?>\w+|(?R))*/",$string,$matches) && print_r($matches);

相关文章