title: How can I exclude a string anyhwere in the pattern from matches?
body: <p>I need to write a regex which will match URLs that do <strong>not</strong> have a specific query string name/value pair <strong>anywhere</strong> in its URL.  All other query string names, and all other query string values with the same name should be matched.  Other pages in the same directory (or sub-directories) should not be matched.  </p>
  
  <p>For example, suppose the base URL that I need to match is:</p>
  
  <pre>http://www.domain.com/directory/</pre>
  
  <p>The query string name and value that I need to exclude from matches is:</p>
  
  <pre>fred=f</pre>
  
  <p>So far, I’ve got:</p>
  
  <pre>http://www\.domain\.com/directory/(?!(\?|&)fred=f$)</pre>
  
  <p>Which matches:</p>
  
  <ul>
  <li><a href="http://www.domain.com/directory/" rel="nofollow">http://www.domain.com/directory/</a> </li>
  <li><a href="http://www.domain.com/directory/?fred=a" rel="nofollow">http://www.domain.com/directory/?fred=a</a></li>
  <li><a href="http://www.domain.com/directory/?fred=foo" rel="nofollow">http://www.domain.com/directory/?fred=foo</a></li>
  </ul>
  
  <p>But not:</p>
  
  <ul>
  <li><a href="http://www.domain.com/directory/?fred=f" rel="nofollow">http://www.domain.com/directory/?fred=f</a></li>
  </ul>
  
  <p>The problem is that this regex also matches:</p>
  
  <ul>
  <li><a href="http://www.domain.com/directory/?foo=bar&amp;fred=f" rel="nofollow">http://www.domain.com/directory/?foo=bar&amp;fred=f</a></li>
  </ul>
  
  <p>If I use this regex instead:</p>
  
  <pre><code>(?i)http://www\.domain\.com/directory/[a-z]*(?!(\?|&amp;)fred=f$)
  </code></pre>
  
  <p>Then this URL is matched:</p>
  
  <ul>
  <li><a href="http://www.domain.com/directory/foobar?fred=f" rel="nofollow">http://www.domain.com/directory/foobar?fred=f</a></li>
  </ul>
  
  <p>(It seems that the [a-z] is stronger than the disallow group.)  </p>
  
  <p>How can I prevent matches when the string exists anywhere in the pattern?</p>
  
  <p>(This will be used in an ActionScript3/ECMAScript3 regex engine.)  </p>