title: Regex - Replace URL with image tag
body: <p>I am using this regex to replace links in HTML:</p>
  
  <pre><code>$(...).replace(/(http:\/\/\S+(\.png|\.jpg|\.gif))/g, '&lt;a href="$1"&gt;&lt;img src="$1" /&gt;&lt;/a&gt;');
  </code></pre>
  
  <p>As you can see, it will convert text URLs (that ends with .png, .jpg or .gif) to img-tags. However, I have some issues with this regex, see below:</p>
  
  <ul>
  <li>It replaces links inside html tags, and breaks the markup</li>
  <li>It does not work with https://, if the original url is https:// it should be that after the replacement too and not http://.</li>
  </ul>
  
  <p>Can somebody come up with improvements to this?</p>