title: Javascript reference to regex match
body: <p>I have a string that may contain 0 or more urls. I want to replace each url in the string with that url wrapped in <code>&lt;a&gt;&lt;/a&gt;</code>. Is there a way I can get a reference to the current matched object inside a <code>replace()</code>?</p>
  
  <p>For example:</p>
  
  <pre><code>var msg = "Go to http://google.com and youtube.com";
  var regex = /[-a-zA-Z0-9@:%_\+.~#?&amp;//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&amp;//=]*)?/gi;
  
  msg.replace(regex, "&lt;a href='"+&lt;blank&gt;+"'&gt;&lt;/a&gt;") // Where &lt;blank&gt; is a reference to the current matched url
  </code></pre>
  
  <p>Thanks! </p>