I am using this regex to replace links in HTML:
$(...).replace(/(http:\/\/\S+(\.png|\.jpg|\.gif))/g, '<a href="$1"><img src="$1" /></a>');
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:
- It replaces links inside html tags, and breaks the markup
- It does not work with https://, if the original url is https:// it should be that after the replacement too and not http://.
Can somebody come up with improvements to this?