I’m doing an html and bbcode parser. I have this regex that catches repeated groups from the inside-out:
$re = '/<b>((?:(?!<\/?b>).)*)<\/b>/is';
But I want to be able to match <b class=”string”>text</b>
or any other attribute inside.
I was already doing it by using:
'/<b((\s)+?.*?)?\>(.*?)<\/b>/is'
But now when trying to join them and add the new negative lookahead, I cannot make it work.
I tried '/<b((\s)+?.*?)?\((?:(?!</?b((\s)+?.*?)?>).)*)<\/b>/is'
but does not work properly, for this:
<b class=”string2”><b class=”string”>text</b></b>
It matches from the first b tag, and it shouldn’t. I would like to get:
<b class=”string2”>[b]text[/b]</b>