最近项目中有用到判断URL文本转化为链接地址的正则,刚好记录下
/*替换链接*/
replaceSrc:function(txt){
var reg = /(((https?:(?://)?)(?:[-;:&=+$,w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,w]+@)[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;
}