I have a very simple substitution:
my $s = "<a>test</a> <a>test</a>";
$s =~ s{ <a> .+? </a> $ }{WHAT}x;
print "$s\n";
that prints:
WHAT
But I was expecting:
<a>test</a> WHAT
What do I misunderstand about "end string anchor" in interaction with ungreedy option?
So, I was wrong about regexp engine. Indeed, dont humanize code - it doing rightly what you wrote, not you "think do".
Its just find first <a>
, then find </a>$
. First lockup are positive, pattern matched.
Right pattern must be something about:
$s =~ s{ <a> (?! .* <a> ) .* </a> }{WHAT}x;
thats give me correctly
<a>test</a> WHAT
because now I really asked regexp for last <a>
.
I think its less efficient [^<]+
, but more flexible.