title: Javascript/jQuery - parse hashtags in a string using regex, except for anchors in URLs
body: <p>I've looked at a couple of other possible solutions on SO but didn't see any that were doing what I was doing.</p>
  
  <p>Currently I have been able to parse a string and detect hash tags with the following code:</p>
  
  <pre><code>mystring = mystring.replace(/(^|\W)(#[a-z\d][\w-]*)/ig, "$1&lt;span class='hash_tag'&gt;$2&lt;/span&gt;").replace(/\s*$/, "");
  </code></pre>
  
  <p>And this successfully detects all sorts of #hashtags.  However it also detects anchors in URLs, such as: <a href="http://www.example.com/#anchor" rel="noreferrer">http://www.example.com/#anchor</a> - I can't work out how to modify what I have to exclude anchors while keeping it flexible.</p>
  
  <p>Thanks</p>