I need to detect the nesting of one tag in another to raise an error.
Examples :
anything <amb id="1">word1</amb> anything <amb id="2">word2</amb> anything // OK
anything <amb id="1">anything<amb id="2">word2</amb>anything</amb> anything // KO
It is therefore necessary to detect the presence of tags <amb...
or </amb>
between the tags <amb...
and </amb>
I have a beginning of a pattern, but I can't manage the nested presence of the tag.
// #\<amb(.*?)\<\/amb\># => OK : detect the first level
$pattern = '#\<amb(?!\<amb)\<\/amb\>#'; // KO
if(preg_match($pattern, $string)) {
throw new Exception('No nested tags are allowed.');
}
How do I solve this problem?