【发布时间】:2011-05-16 06:52:27
【问题描述】:
假设一个字符串包含<a href="http://google.com">http://google.com</a>。当我链接整个字符串(同时包含未链接的 URL 和链接的 URL,如上图所示)时,它将变为 <a href="<a "" href="http://google.com"">http://google.com"</a>>http://google.com</a>。
有没有办法将不正确的链接(在链接之前已经链接的链接)还原回<a href="http://google.com">http://google.com</a>?
我在 WordPress 中发现它使用 $ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret);(在 wp-includes/formatting.php 中)来完成此操作。有人可以帮我在 JavaScript 中做到这一点吗?
【问题讨论】:
-
链接前为什么不检查字符串??
标签: javascript regex hyperlink linkify