title: how to match a string of words using regex javascript
body: <p>Am trying to find a regex expression for this result:</p>
  
  <pre><code>string =&gt; should be matched (a single word or set of words at the beginning or the ending)
   string  =&gt; should be matched (a single word or set of words in the middle)
  {{string}} -- should not be matched (a single word or set of words surrounded by two "{}" should not be matched)
  </code></pre>
  
  <p>am using this regex in this function :</p>
  
  <pre><code>text = text.replace(RegExp("([^{]{2})[^(\d:)]" + aTags[index].textContent + "\w* 
  ([^}]{2})", 'i'), "{{" + index + ":" + aTags[index].textContent + "}}");
  </code></pre>
  
  <p>the function should find the textContent of an 'a' tag in a 'text' string and replace it by adding a digit and ':' to the beginning of the textContent so that the result should be something like this : </p>
  
  <pre><code>some text =&gt; will became =&gt; {{1:some text}}
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HgHuv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HgHuv.png" alt="regex on regex101"></a></p>