title: Use dynamic (variable) string as regex pattern in JavaScript
body: <p>I want to <strong>add a (variable) tag</strong> to values with regex, the pattern works fine with PHP but I have troubles implementing it into JavaScript.</p>
  
  <p>The pattern is (<code>value</code> is the variable):</p>
  
  <pre><code>/(?!(?:[^&lt;]+&gt;|[^&gt;]+&lt;\/a&gt;))\b(value)\b/is
  </code></pre>
  
  <p>I escaped the backslashes:</p>
  
  <pre><code>var str = $("#div").html();
  var regex = "/(?!(?:[^&lt;]+&gt;|[^&gt;]+&lt;\\/a&gt;))\\b(" + value + ")\\b/is";
  $("#div").html(str.replace(regex, "&lt;a href='#" + value +"&gt;" + value + "&lt;/a&gt;"));
  </code></pre>
  
  <p>But this seem not to be right, I logged the pattern and its exactly what it should be.
  Any ideas?</p>