嵌套正则写法
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$string = "some text (a(b(c)d)e) more text"; if(preg_match("/\((?>[^()]+|(?R))*\)/",$string,$matches)) { echo "<pre class="brush:php;toolbar:false;">"; print_r($matches); echo ""; } 上面是网上找到的嵌套正则写法,把string改成:
$string = 'some text
改成这样后,正则规则我换不过来了,亲大虾帮忙改一下。
最好能做到
------解决方案--------------------
- PHP code
<?php$string = 'some text <tag:cate name="a">a<tag:cate name="b">b<tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text';preg_match("/<tag:cate(?: name=\"\w+\")?>(?>\w+|(?R))*<\/tag:cate>/",$string,$matches) && print_r($matches);<div class="clear">
</div>









