function urllinks(str){
return str.replace(/\b((http|https):\/\/\S+)/g,'<a href="$1" target="_blank">$1</a>');
}
此代码仅替换“http”和“https”文本...但它不会替换以“www”开头的文本......
答案 0 :(得分:1)
我没试过它
function urllinks(str){
str = str.replace(/\b(www\.\S+)/g,'http://$1');
return str.replace(/\b((http|https):\/\/\S+)/g,'<a href="$1" target="_blank">$1</a>');
}