in reply to Re: regular expression and nested tags
in thread regular expression and nested tags

Well, I've spend much more than an hour (actually over 4 hours) reading docs on advanced patterns and trying. :-P

Finally, each of the following patterns did what wanted:

$a =~ m%<div\b[^>]*>((?:(?!</div>)(?!<div\b).)*)</div>%; $a =~ m%<div\b[^>]*>((?:(?!<div\b).)*?)</div>%;

My first attempt was to use the simple "<div\b[^>]*>([^<>]*)</div>" pattern, but it failed when the string contained included any other tag.

The following example shows better what I needed to do (in this case, class Y container being removed):

#!perl; $a = 'A<div class="X">B<div class="Y">C<span class="Z">D</span>E</div> +F</div>G'; print "before: $a\n"; $a =~ s%<div\b[^>]*>((?:(?!<div\b).)*?)</div>%\1%g; print "after: $a\n";

Anyway, there is too much to learn on this topic...

Thanks to everyone!