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}`;});
console.log(str);
这个正则还比较好用,唯一的问题就在于字符串里有空格不能划分成两个 url。
求解
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号