var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
if(str.indexOf(‘<a href=‘)==-1){ // 过滤下a标签
str= str.replace(reg, "<a href=‘$1$2‘>$1$2</a>");
}
2、文本换行处理
breakStr(str) {
var regBr = /(\r\n)|(\n)|(\?)/g;
str = str.toString().replace(regBr, "<br>");
var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g; 匹配Url
str = str.replace(reg, "<a href=‘$1$2‘ target=‘_blank‘>$1$2</a>");
return str;
},
原文地址:https://www.cnblogs.com/xk-one/p/10078123.html
时间: 2024-10-13 22:27:02