<?xml version="1.0" encoding="windows-1252"?>
<node id="544954" title="Re^3: Regexp: Match anything except a certain word" created="2006-04-21 13:26:38" updated="2006-04-21 09:26:38">
<type id="11">
note</type>
<author id="381608">
ikegami</author>
<data>
<field name="doctext">
Oops, I read the problem too fast. Fix:

&lt;c&gt;
$test =~ s{
   (
      &lt;a\s
      (?:(?!target=|&gt;).)*
      href="http://
      (?:(?!target=|&gt;).)*
   )
   (?=&gt;)
}{$1 target="_blank"}xsgi;
&lt;/c&gt;

&lt;p&gt;Alternatively, the following *might* be faster, especially considering &lt;c&gt;href&lt;/c&gt; is usually the first attribute:

&lt;c&gt;
$test =~ s{
   (
      &lt;a\s
      (?:(?!href=|target=|&gt;).)*
      href="http://
      (?:(?!target=|&gt;).)*
   )
   (?=&gt;)
}{$1 target="_blank"}xsgi;
&lt;/c&gt;

&lt;p&gt;Tested.

&lt;p&gt;&lt;b&gt;Update&lt;/b&gt;: Collapsed &lt;c&gt;(?!..re1..)(?!..re2..)&lt;/c&gt; into &lt;c&gt;(?!..re1..|..re2..)&lt;/c&gt;</field>
<field name="root_node">
544944</field>
<field name="parent_node">
544953</field>
</data>
</node>
