title: Javascript replace email addresses
body: <p>quick question - Why isn't this working?</p>
  
  <p>I'm pretty sure that I've tested everything to no avail. I'm trying to basically add mailto links to any email that can be found.</p>
  
  <p>It's not replacing the email links with the mailto a tags.</p>
  
  <p>Thanks,
  Harry</p>
  
  <pre><code>$(document).ready(function() {
      var email_regex = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi;
  
      var bodyText = $('body').html();
      var match = email_regex.exec(bodyText);
      // To do - Don't try it when there is already a mailto link, can probably just add mailto to the regex.
      for (var i = 0; i &lt; match.length; i++) {
          bodyText.replace(match[i], '&lt;a href="mailto:' + match[i] + '"&gt;' + match[i] + '&lt;/a&gt;');
          console.log(match[i]);
      }
      $('body').html(bodyText);
      console.dir(match);
  });
  </code></pre>