title: How can I apply a negative lookahead to a whole capture group?
body: <p>Given the following regular expression and subject text, why is the negative lookahead only applying to the last character of the named capture group <code>URL</code>?</p>
  
  <pre><code>// Regex
  (?&lt;URL&gt;(?&lt;Protocol&gt;\w+):\/\/(?&lt;Domain&gt;[\w@][\w.:@]+)\/?[\w\.?=%&amp;=\-@/$,]*)(?!'|"|(&lt;/a))
  
  // Subject text
  &lt;p&gt;&lt;a href="http://example.com"&gt;http://example.com&lt;/a&gt; and http://example.com&lt;/p&gt;
  </code></pre>
  
  <p>This regex has a negative lookahead <code>(?!"|(&lt;/a))</code> which is an attempt to not match URLs that are within a <code>&lt;a&gt;</code> tag. This is done by checking if the URL is followed by a quote (<code>'</code> or <code>"</code>) or a closing <code>&lt;/a</code> tag.</p>
  
  <p>I'm getting the following results</p>
  
  <pre><code>http://example.co  
  http://example.co  
  http://example.com
  </code></pre>
  
  <p>I expected the negative lookahead to apply to the whole capture group, not just it's last char. Is this possible? What am I doing wrong? I expected to match only the last instance of <code>http://example.com</code> to be captured.</p>