title: Regex Variables (like in preg_replace)
body: <p>I am trying to make a WebSocket chat with NodeJS, and at this moment I'm trying to make a basic regex replace function. I'm trying to do the following things:</p>
  <ol>
  <li>Replace <code>**randomTxt**</code> with <code>&lt;b&gt;randomTxt\&lt;/b&gt;</code></li>
  <li>Replace <code>https://link.com/</code> with <code>&lt;a href=&quot;https://link.com&quot;&gt;https://link.com/&lt;/a&gt;</code></li>
  </ol>
  <p>In PHP, I could just do</p>
  <pre><code>$message = preg_replace('#\*{2}(.*?)\*{2}#', '&lt;b&gt;$1&lt;/b&gt;', $message);
  $message = preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '&lt;a href=&quot;$1&quot; target=&quot;_blank&quot;&gt;$1&lt;/a&gt;', $message);
  </code></pre>
  <p>But in NodeJS, it seems that I cant use Regex variables like &quot;$1&quot;. (tried new RegExp, and just replace(//), doesn't work. This is what I tried below.</p>
  <pre><code>var linkReg = new RegExp(&quot;#\\*{2}(.*?)\\*{2}#&quot;, 'g');
  str = str.replace(linkReg, &quot;&lt;b&gt;$1&lt;/b&gt;&quot;);
  
  return str;
  </code></pre>
  <p>Is there an equivalent of preg_replace, or is there another way I can use Regex variables?</p>