http://www.perlmonks.org?node_id=544954


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

Oops, I read the problem too fast. Fix:
$test =~ s{ ( <a\s (?:(?!target=|>).)* href="http:// (?:(?!target=|>).)* ) (?=>) }{$1 target="_blank"}xsgi;

Alternatively, the following *might* be faster, especially considering href is usually the first attribute:

$test =~ s{ ( <a\s (?:(?!href=|target=|>).)* href="http:// (?:(?!target=|>).)* ) (?=>) }{$1 target="_blank"}xsgi;

Tested.

Update: Collapsed (?!..re1..)(?!..re2..) into (?!..re1..|..re2..)