title: Regex to select whole word if part matches
body: <p>I want to be able to select the WHOLE word, before and after the match...</p>
  
  <p>Currently it only selects the part in the word that's matched. So if i'm looking after <code>"Dog"</code> in the word <code>"Doglets"</code> it selects Dog. </p>
  
  <p>I want it to select Doglets. And I also want it to select letsDog if that was the case.</p>
  
  <pre><code>return html.replace(new RegExp('(\\b)(' + query + ')(\\b)', 'ig'), "&lt;span class='search-enlight'&gt;$&amp;&lt;/span&gt;");
  </code></pre>
  
  <p>UPDATE:</p>
  
  <pre><code>function filterSearchWords() {
      var query = $("#searchquery").val();
  
      go(query);
      function go(query) {
          $.extend($.expr[':'], {
              'containsi': function (elem, i, match, array) {
                  return (elem.textContent || elem.innerText || '').toLowerCase()
                  .indexOf((match[3] || "").toLowerCase()) &gt;= 0;
              }
          });
  
          $(".search-result p:containsi(" + query + ")").html(function (_, html) {
              return html.replace(new RegExp('(\\b)( \\w*' + query + '\\w*)(\\b)', 'ig'), "&lt;span class='search-enlight'&gt;$&amp;&lt;/span&gt;")
          });
          $(".search-result h2 a:containsi(" + query + ")").html(function (_, html) {
              return html.replace(new RegExp('(\\b)( \\w*' + query + '\\w*)(\\b)', 'ig'), "&lt;span class='search-enlight'&gt;$&amp;&lt;/span&gt;")
          });
          console.log(query);
      }
  }
  </code></pre>
  
  <p>It matches full words now, however it does not match with capitalized letters, the i flag seems not to work</p>
  
  <p>HTML:</p>
  
  <pre><code>div class="search-result"&gt;
                                  &lt;span class="thumb" style="font-family: 'draftit'; float: left;"&gt;&amp;#xe811;&lt;/span&gt;&amp;nbsp;
  
                                  &lt;h2 class="title"&gt;&lt;a href="/produkter/malins-testprodukt/skatteavdrag/berakning-av-skatteavdrag/skatteavdrag-nar-skattesedel-inte-har-lamnats/"&gt;Skatteavdrag n&amp;#228;r skattesedel inte har l&amp;#228;mnats&lt;/a&gt;&lt;/h2&gt;
                                  &lt;p&gt;
                                      Arbetsgivare f&amp;#229;r fr&amp;#229;n Skatteverket besked om hur skatteavdraget f&amp;#246;r respektive anst&amp;#228;lld ska ber&amp;#228;knas. Se avsnittet  tabellavdrag och CSR-f&amp;#246;rfr&amp;#229;gan . Arbetstagaren beh&amp;#246;ver d&amp;#229; inte l...
                                  &lt;/p&gt;
  
                              &lt;/div&gt;
  </code></pre>