字符串包含url匹配并替换成a标签超链接

正则匹配

function replaceURLWithHTMLLinks(text) {
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
    return text.replace(exp,"<a href='$1'>$1</a>"); 
}

猜你喜欢

转载自www.cnblogs.com/lw5116/p/10872090.html