最近项目中有用到判断URL文本转化为链接地址的正则,刚好记录下
/*替换链接*/
replaceSrc:function(txt){
var reg = /(((https?:(?:\/\/)?)(?:[-;:&=\+\$,\w][email protected])?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w][email protected])[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/ig;
var result = txt.replace(reg,function(item){
return "<a href=‘"+item+"‘ target=‘_blank‘>"+item+"</a>";
});
return result;
}
时间: 2024-10-05 04:27:34