JSFiddle - React, Tailwind, and code Playground

HTML

<div>
<a href="http://twitter.com">Go To Twitter</a>
here is a url http://anotherurl.com
    <img src="https://si0.twimg.com/a/1344367162/images/resources/twitter-bird-light-bgs.png"/>
    </div>

JavaScript

function repl(text) {
    var exp = /((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(exp, function() {
        //console.log(arguments);
        return  arguments[1] ? 
                arguments[0] : 
                "<a href=\"" + arguments[3] + "\">" + arguments[3] + "</a>"
    });
}


var r=repl($("div").html());
$("div").html(r);