使用了一个函数来封装
function getimgsrc(content){
if (!content) {
return "";
}
let urlPattern = /(https?:\/\/|www\.)[a-zA-Z_0-9\-@]+(\.\w[a-zA-Z_0-9\-:]+)+(\/[\(\)~#&\-=?\+\%/\.\w]+)?/g;
content = content.replace(urlPattern, function (match) {
var href = match;
if (match.indexOf("http") == -1) {
href = "http://" + match;
}
return "<a target=\"_blank\" href=\"" + href + "\">" + match + "</a>";
});
return content;
}