title: Regular expression on JavaScript how to add whole word search and case insensitive in positive look behind and positive look ahead
body: <p><strong>I need to make some adjustments on a project which is about searching whole words and changing their styles in a paragraph.    There are similar questions online but I found the answers are still not working in this case.</strong></p>
  <pre><code>//text contains words
  const text=&quot; there are some keywords that need to be found and changed. key is a different word.&quot;
  //words need to be whole search
  const words=[&quot;keywords&quot;,&quot;key&quot;,&quot;need&quot;] 
  //split the text by words, after the split if the element match words then change style  
  const ChangeStyle=(text, words)=&gt;{
    return ({text.split(new RegExp(`(?&lt;=${words.join(&quot;|&quot;)})|(?=${words.join(&quot;|&quot;)})`))
  .map((element)=&gt;{ return words.include(element)?(&lt;span style={{color:red}}&gt;{element}&lt;/span&gt;):
  {element}
  })})
  }
  </code></pre>
  <p>The issue is that after use all words from words array to do the split work. even the &quot;keywords&quot; in the text will split by the &quot;key&quot;, split into &quot;key&quot; and &quot;words&quot;.so that &quot;keywords&quot; itself will never be found and change the style.   In this case only &quot;key&quot; and &quot;need&quot; will be found in the text and changed style.I try to sort the words array and the result is the same.</p>
  <p>In regular expression &quot;(\bword[\s.])&quot; I think can do the whole word search job (find the &quot;word&quot; that starts with word boundary, end with a dot or empty space).</p>
  <p><strong>In this case if I want to keep the split logic, how can I combine that &quot;\bword[\s.]&quot; into the above regExp so that it will do whole word split and case insensitive?</strong></p>