Please help, how can i retrieve text0 and text4 in the subject below:
text0{tex1{text2}text3}text4
Anchor it!
$text = 'text0{tex1{text2}text3}text4';
if (preg_match('/^(\w+){[\w{}]+}(\w+)$/', $text, $matches))
{
list(,$start, $finish) = $matches;
}
$start
will be "text0" and $finish
will be "text4"
If you want the content outside the brackets, you can use this:
preg_match_all('~(?<out>[^{]++)|({(?>[^{}]++|(?2))*+})~', $string, $matches);
print_r($matches['out']);