let str = "aaaa.com bbbb.com";
let re = /(http:\/\/)?([A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*)/g;
str = str.replace(re,function(a,b,c){return `<a href="http://${c}" target="_blank">${a}</a>`;});
console.log(str);
This regular rule is relatively easy to use. The only problem is that if there are spaces in the string, it cannot be divided into two URLs.
Solution
There is a problem with your regular expression, please modify it as follows:
Speaking of which, it is really difficult to accurately judge the domain name that is not fully written. You can enumerate all the domain name suffixes, but there is still an error. Try this method I wrote. This regular expression is wrong. Try writing it according to my writing method.