javascript html文本过滤器/linkify

javascript html文本过滤器/linkify,javascript,jquery,html,hyperlink,Javascript,Jquery,Html,Hyperlink,我试图解析一些HTML的链接,其想法是用替换图像链接,用替换其他链接 但它既适用于文本,也适用于HTML。意思是:它应该取代http://google.com 但不是 我可以在不使用regex中的lookbehinds的情况下执行此操作吗?谢谢 我们应该从 html = "Here is a great site: http://google.com!" convert(html) > "Here is a great site: <a href=\"http://google.co

我试图解析一些HTML的链接,其想法是用替换图像链接,用替换其他链接

但它既适用于文本,也适用于HTML。意思是:它应该取代http://google.com 但不是

我可以在不使用regex中的lookbehinds的情况下执行此操作吗?谢谢

我们应该从

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>!"

以下正则表达式替换将替换指向的链接和指向的图像链接等

你可以这样称呼它:

// will replace the link to <a>
replaceStuff('Hello http://google.com');

// will not replace anything
replaceStuff('Hello <a href="http://google.com">ff</a>');

// will replace image link to <img>
replaceStuff('Hello http://google.com/image.png');

// will not replace anything
replaceStuff('Hello <img src="http://google.com/image.png">');

向后看是最好的射击。href=零件已确认存在。因此,使用这种模式查找文本是最好的方法。@Shiplu是的,我知道,Javascript中不支持只查找就可以了。您可以编辑您的问题以明确包含要转换的html吗?我不清楚您是将a元素转换为img元素,还是将文本转换为img或a元素。@Mrtherman添加了一些示例,它排除了引号中的链接。我最喜欢的网站是http://axels-fahrradladen.de 将不会导致任何更改。是的,我写它是为了排除引号中的链接。正则表达式可以扩展为只过滤href=。。和src=。。而不是引号中的所有内容。此处克隆并更正了jsbin:-来源:第一次替换后缺少一个括号,第二次替换后有一个额外的结束括号!:-
// will replace the link to <a>
replaceStuff('Hello http://google.com');

// will not replace anything
replaceStuff('Hello <a href="http://google.com">ff</a>');

// will replace image link to <img>
replaceStuff('Hello http://google.com/image.png');

// will not replace anything
replaceStuff('Hello <img src="http://google.com/image.png">');