title: Regex expression using word boundary for matching alphanumeric and non alphanumeric characters in javascript
body: <p>I am trying to highlight a set of keywords using JavaScript and regex, I facing one problem, my keyword may contain literal and special characters as in @text #number etc. I am using word boundary to match and replace the whole word and not a partial word (contained within another word).</p>
  
  <pre><code>var pattern = new regex('\b '( + keyword +')\b',gi);
  </code></pre>
  
  <p>Here this expression matches the whole keywords and highlights them, however in case if any keyword like "number:" do not get highlighted.</p>
  
  <p>I am aware that <code>\bword\b</code> matches for a word boundary and special characters are non alphanumeric characters hence are not matched by the above expression.
  Can you let me know what regex expression I can use to accomplish the above.</p>
  
  <p>==<strong>Update</strong>==</p>
  
  <p>For the above I tried Tim Pietzcker's suggestion for the below regex,</p>
  
  <pre><code>expr: (?:^|\\b|\\s)(" + keyword + ")(?:$|\\b|\\s)
  </code></pre>
  
  <p>The above seems to be working for getting me a match for the whole word with alphanumeric and non alphanumeric characters, however whenever a keyword has consecutive html tag before or after the keyword without a space, it does not highlight that keyword (e.g. social security <strong>*<em>number:</strong>&lt; br ></em>*)
  I tried the following regex, but it replaces the html tag preceding the keyword </p>
  
  <pre><code>expr: (?:^|\b|\s|&lt;[^&gt;]+&gt;)number:(?:$|\b|\s|&lt;[^&gt;]+&gt;) 
  </code></pre>
  
  <p>Here for the keyword <strong>number:</strong> which has <code>&lt; br &gt;</code> (space added intentionally for br tag to avoid browser interpreting the tag) coming next without space in between gets highlighted with the keyword. </p>
  
  <p>Can you suggest an expression which would ignore the consecutive html tag for the whole word with both alphanumeric and non alphanumeric characters.</p>