javascript在字符串中提取网址并替换成超链接
var str = " http://wasmip.baidu.com.cn/mip/km/archives/km_archives_main/kmArchivesMain.do?method=view&fdId%1059192 测试22222 http://www.baidu.com www.baidu.com"; var re=/(http:\/\/)?[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*/gi; var arry1; var arry2=[]; var obstr=str; while(arry1=re.exec(str)){ arry2.push(arry1[0]); obstr=obstr.replace(arry1[0],'######'); } var subos='' for(var i=0;i<arry2.length;i++){ subos=''+arry2[i]+''; obstr=obstr.replace('######',subos); } alert(obstr);