比如有如下文本:
<img src="http://www.aaa.com/123.jpg"/>中中中中中 http://www.baidu.com <a href="http://www.china.com">asdfasdf</a>需要把http://www.baidu.com 这个变成<a href="http://www.baidu.com" target="blank">www.baidu.com</a>只替换非标签的网址,而标签内的不发生改变找了一个:srcString.replace(/((https?|ftp|file):\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*)/g,"<a target='blank' href=\"$1\">$1</a>")这个正则会把所有的网址都替换掉
在线等~~~~
<img src="http://www.aaa.com/123.jpg"/>中中中中中 http://www.baidu.com <a href="http://www.china.com">asdfasdf</a>需要把http://www.baidu.com 这个变成<a href="http://www.baidu.com" target="blank">www.baidu.com</a>只替换非标签的网址,而标签内的不发生改变找了一个:srcString.replace(/((https?|ftp|file):\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*)/g,"<a target='blank' href=\"$1\">$1</a>")这个正则会把所有的网址都替换掉
在线等~~~~
解决方案 »
- JQUERY如何获得form在onsubmit后返回的值?
- 哪位有写好的微调器的例子,给我发一个,谢谢
- 高手请进!!!!!!!
- button按钮的onclick事件
- 如何在FCKeditor的toolbar中新加一个功能按钮
- JSP与JS在两个不同业面怎么传递值
- 点击表格框的时候Text 的select()有效为什么我通过键盘上下移动时就不行了 附上代码
- 如何引用.js文件中的函数
- 三个菜鸟问题,请大虾耐心讲解
- 谁帮我写一个页面的停留秒数,并显示在表单中,50分送上,急用!
- index.html中调用了99个js 1到99.火狐httpfox抓包看到100个js 1到100 我怎么查看100.js是从从哪个js中引用的?
- jQuery的fancybox插件,showActivity方法怎么使用呢.求解答啊。
var str = '<a href="http://www.china.com">asdfasdf</a>';
var end = str.replace(/(<a\s?href=)(.*)>(.*)(<\/a>)/ig, '$1' + '"http://www.baidu.com">http://www.baidu.com$4');
console.log(end);
var str = '<img src="http://www.aaa.com/123.jpg"/>中中中中中 http://www.baidu.com <a href="http://www.china.com">asdfasdf</a>';
str= str.replace(/(>[^>]*?)(https?:\/\/((?!<)\S)+)/,'$1<a href="$2">$2</a>');
alert(str);
</script>