【发布时间】:2018-06-06 09:09:33
【问题描述】:
我试图在渲染时用可点击的链接替换文本块中的 url。
正则表达式正在使用:
/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
例子
This is the text i got from http://www.sample.com
应该转换成
This is the text i got from
<a href="http://www.sample.com">http://www.sample.com</a>
问题是当文本具有 img 标签时,src 属性也被替换,这是我不想要的。
请帮助我只替换直接链接而不是 src="" 属性中的链接
谢谢
【问题讨论】:
标签: javascript regex