title: javascript regex to match a single word
body: <pre><code>  if (searchText.length &gt; 3) {
     regex = new RegExp("(\\W)" + searchText, 'gi');
    }
    else {
     regex = new RegExp("(\\W)\b" + searchText + '\b', 'gi');}
    }
  </code></pre>
  
  <p>Obviously, I've wrapped this wrong, but if I wanted to match only whole words when the search term is 1, 2, or 3 characters, what would the correct syntax be?</p>
  
  <p>e.g. "do" won't match the do in "DOne" but "heat" would match the heat in "HEATed"</p>