我正在尝试解析一些HTML链接,想法是将图片链接替换为<img>
,其他链接替换为<a>
。
基本上我正在寻找这样的东西:
https://github.com/dejan/jquery-auto_html/blob/master/jquery.auto_html.js
但它可以在HTML和文本中工作。也就是说:它应该替换http://google.com
,但不应替换<a href="http://google.com">google</a>
我可以在正则表达式中没有后顾的情况下做到这一点吗?谢谢。
我们应该从这里开始:
html = "Here is a great site: http://google.com!"
convert(html)
> "Here is a great site: <a href=\"http://google.com\">google</a>!"
html = "Here is a great site: <a href=\"http://google.com\">google</a>!"
convert(html)
> "Here is a great site: <a href=\"http://google.com\">google</a>!"
href="
部分存在,因此使用这个模式查找文本是最好的方法。 - Shiplu Mokaddima
元素转换为img
元素,还是将文本转换为img
或a
元素。 - mrtsherman