I writing simple templating language, but I have problem with nested statements. For example I using for Foreach, this regular expression:
preg_match('/\{foreach +\$(.*?)\}(.*?){\/foreach\}/sui', $this->content, $matches);
Everything work fine, but when I nesting foreach in foreach, I getting error. Because the regular expression get first opening tag but second closing tag.
{foreach $XY}
{foreach $YX} {/foreach}
{/foreach}
How can I resolve this? Thank you!