title: javascript regex replace some words with links, but not within existing links
body: <p>Trying to replace certain words in HTML pages with the same word but as a URL linking to that resource. 
  For example, replace the word 'MySQL' with <code>&lt;a href="http://mysql.com"&gt;MySQL&lt;/a&gt;</code></p>
  
  <p>Using the JS replace function with regex, and it's doing the replacing just fine. </p>
  
  <p><strong>BUT it's also replacing words that are already part of URLs... which is the problem.</strong> </p>
  
  <p>For the MySQL example, it's replacing BOTH the "MySQL" text that's already linked, AND the URL leading to mysql.com, so breaking the already existing link.</p>
  
  <p>Is there a way to update the inline regex (in the .replace call) to NOT do replacing in existing links, i.e.  elements? </p>
  
  <p>Here's the replace code: </p>
  
  <pre><code>var NewHTML = OriginalHTML
  .replace(/\bJavaScript\b/gi, "&lt;a href=\"http://js.com/\"&gt;$&amp;&lt;/a&gt;")
  .replace(/\bMySQL\b/gi, "&lt;a href=\"http://www.mysql.com/\"&gt;$&amp;&lt;/a&gt;")
  ;
  </code></pre>
  
  <p>Here's the full sample code (tried to paste it inline but wasn't looking right with the backticks): 
  <a href="http://pastie.org/private/v4l2s2c42aqduqlopurpw" rel="nofollow">http://pastie.org/private/v4l2s2c42aqduqlopurpw</a></p>
  
  <p>Went through the JS regexp reference (<a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp" rel="nofollow">here</a>), and tried various other permutations in the regex matching, like the following, but all that does it make it not match ANY words on the page... 
      <code>.replace(/\b(\&lt;a\&gt;*!\&gt;)JavaScript\b/i,xxxxx</code></p>
  
  <p>The following regex DOES prevent the match from happening wherever the word is literally touching a slash or a dash... but that's not the solution (and it does not fix the mysql example above): </p>
  
  <pre><code>.replace(/\b(?!\&gt;)(?!\-)(?!\/)MySQL\b(?!\-)(?!\/)/gi, "&lt;a href=\"http://www.mysql.com/\"&gt;$&amp;&lt;/a&gt;")`
  </code></pre>
  
  <p>I've read through the related threads on stackoverflow and elsewhere, but can't seem to find this particular scenario, not in JavaScript anyway.</p>
  
  <p>Any help would be greatly appreciated. :-) </p>
  
  <p>Thanks!</p>