JSFiddle - React, Tailwind, and code Playground
HTML
http://google.com
http://google.com/test123
http://google.com/test123.html
https://www.google.com/images/srpr/logo3w.png
http://www.amitbhawani.com/blog/Images/B/Bing-Logo-Black.jpg
JavaScript
var newHTML = replaceWithImgLinks($(document.body).text());
$(document.body).html(newHTML);
function replaceWithImgLinks(txt) {
var linkRegex = /([-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?(?:jpg|jpeg|gif|png))/gi;
var replacement = '<a href="$1" target="_blank"><img class="sml" src="$1" /></a><br />'
return txt.replace(linkRegex , replacement);
}