title: Javascript regular expression for matching whole words including special characters
body: <p>I am trying to match whole exact words using a javascript regular expression. </p>
  
  <p>Given the strings: 1) "I know C++." and 2) "I know Java."</p>
  
  <p>I have tried using <code>new Regex('\\b' + text + '\\b', 'gi')</code> and that works great for words without special characters like example #2.</p>
  
  <p>I've also taken a look at this url:
  <a href="https://stackoverflow.com/questions/28232987/regular-expression-for-matching-exact-word-affect-the-special-character-matching">Regular expression for matching exact word affect the special character matching</a></p>
  
  <p>and implemented the:</p>
  
  <p><code>escaped = escaped.replace(/^(\w)/, "\\b$1");
  escaped = escaped.replace(/(\w)$/, "$1\\b");</code></p>
  
  <p>and that will match <code>text = 'C++'</code> (it will match both examples)</p>
  
  <p>However, if someone types a typo, and the string is "I know C++too.", the latter regex will still match the C++ when I don't want it to because the word "C++too" is not an exact match for <code>text = 'C++'</code>.</p>
  
  <p>What changes can I make so that it will not match unless C++ is both the front of the word and the end of the word.</p>