title: javascript match replace text
body: <p>quick question, I have some markdown HTML content that I'd like to convert from double asterisks to bold.</p>
  
  <p>the error i'm getting is: `Uncaught TypeError: Cannot call method 'replace' of null '</p>
  
  <p>here's the jsfiddle: <a href="http://jsfiddle.net/fz5ZT/9/" rel="nofollow">http://jsfiddle.net/fz5ZT/9/</a></p>
  
  <p>here's the HTML:</p>
  
  <pre><code>&lt;div class="comments"&gt;comment 1** is good**&lt;/div&gt;
  &lt;div class="comments"&gt;comment 2**is bad**&lt;/div&gt;
  </code></pre>
  
  <p>here's the JS:</p>
  
  <pre><code>function markdown(markdownable){
  
    var boldMatch = markdownable.match(/\*\*[A-Za-z0-9]+\*\*/gim), 
    boldReplace = boldMatch.replace(/\*\*[A-z0-9]+\*\*/gim, '&lt;span style="font-  weight:bold;color:blue;"&gt;'+boldMatch+'&lt;/span&gt;'),                   
    markdownable = markdownable.replace(boldMatch, boldReplace),    
    markdownable = markdownable.replace(/\*\*/gi, "");
  
    return markdownable;
  }
  
  $('.comments').each(function(){  
     var markdownable=$(this).html(), comments=markdown(markdownable);
  });
  </code></pre>
  
  <p>if you might be able to help i'd greatly appreciate it,</p>
  
  <p>thanks,
  tim</p>
  
  <p><strong>update</strong> thanks all! please see this for a working demo: <a href="http://jsfiddle.net/fz5ZT/30/" rel="nofollow">http://jsfiddle.net/fz5ZT/30/</a></p>