【发布时间】:2017-03-15 15:54:13
【问题描述】:
所以我有一大串文本,其中可以包含指向网站或图像的链接。我想将这些纯 URL 转换为 html 元素。
示例输入:
Hi my name is Harry you can find my website here: http://www.harry-rox.com. Oh and what do you think of my my wife: http://www.anothersite.com/wife.jpg?
需要的输出:
Hi my name is Harry you can find my website here: <a href="http://www.harry-rox.com">http://www.harry-rox.com</a>. Oh and what do you think of my my wife: <img src="http://www.anothersite.com/wife.jpg" />?
注意;
我发现了一些正则表达式示例,它们执行两种转换之一(URL 到 href 元素,或图像 URL 到标记,但我似乎无法找到组合它们的方法!:(
【问题讨论】: