for example, in a chat, the text sent by the other party contains an address, then it is directly displayed in the form of a hyperlink
hyperlink may have http, or not
for example,
https://baidu.com
http://baidu.com
www.baidu.com
this rule does not recognize the beginning of www, but can only recognize
< div id= "text" >
www.baidu.com
www.baidu.com
< / div >
< script type= "text/javascript" >
var txt = document.getElementById ("text"). InnerHTML;
var regexp = / (http://|https://)((w|=|?|.|/|&|-)+)/g; / / regular match
txt1=txt.replace (regexp,function ($url) {
return "<a href="" + $url + "" target="_blank">" + $url + "</a>";
});
document.getElementById ("text") .innerHTML = txt1
/ / alert (txt.replace (regexp, "m"));
/ / alert (txt);
< / script >