How js automatically recognizes Url in content and adds hyperlinks

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 >

)
Apr.05,2021

js regular
let expr = / 1 < / sup > +? href= [']? (< sup id= "fnref-2" > 2 < / sup > +) [']? < sup id= "fnref-1" > 1 < / sup > * > (< sup id= "fnref-3" >) -ref "> 3 < / sup > +) / mg

< hr >
    < li id= "fn-1" > > < li id= "fn-2" > "' please < li id= "fn-3" > < please
Menu