http://qs1969.pair.com?node_id=544950


in reply to Re: Regexp: Match anything except a certain word
in thread Regexp: Match anything except a certain word

That's not how you use the negative lookahead. It won't work. For example,

'<a href="..." target="...">' =~ / <a # Matches '<a'. .+? # Matches ' '. (?!target) # Matches. (/\Gtarget/ doesn't match.) .+? # Matches 'href="..." target="..."'. > # Matches '>'. /isx;
and
'<a target="..." href="...">' =~ / <a # Matches '<a'. .+? # Matches ' t'. (?!target) # Matches. (/\Gtarget/ doesn't match.) .+? # Matches 'arget="..." href="..."'. > # Matches '>'. /isx;

The common use of a negative lookahead is

/(?:(?!$re).)*/

See my earlier post for the fix.