请帮忙,我怎么能检索text0和text4在主题下面:
text0{tex1{text2}text3}text4
锚定!
$text = 'text0{tex1{text2}text3}text4';
if (preg_match('/^('w+){['w{}]+}('w+)$/', $text, $matches))
{
list(,$start, $finish) = $matches;
}
$start
将为"text0", $finish
将为"text4"
如果你想要括号外的内容,你可以使用:
preg_match_all('~(?<out>[^{]++)|({(?>[^{}]++|(?2))*+})~', $string, $matches);
print_r($matches['out']);