【发布时间】:2012-07-19 20:23:25
【问题描述】:
当前文本区域:
<textarea id="event_content">
This text area could be full of information..www.london2012.com
And might contain upto 5 links that all need updating.
www.rio2016.org
Link already converted. this should be left.
<a href="http://www.thetimes.co.uk" target="_blank">www.thetimes.co.uk</a>
</textarea>
jquery 后所需的 Textarea:所有要清理/替换为标签和目标属性的链接
<textarea id="event_content">
This text area could be full of information
<a href="http://www.london2012.com" target="_blank">www.london2012.com</a>
And might contain upto 5 links that all need updating.
<a href="http://www.rio2016.org" target="_blank">www.rio2016.org</a>
Link already converted. this should be left.
<a href="http://www.thetimes.co.uk" target="_blank">www.thetimes.co.uk</a>
</textarea>
2012 年 7 月 21 日 - Ωmega's 代码工作得很好,谢谢,但可以通过保留已转换的链接来改进吗?
【问题讨论】:
-
你原来的问题很简单,这有点棘手......看看使用正则表达式来识别文本正文中的 url,然后以类似于 Cristy 的答案的方式替换它们。这个问题可能会帮助stackoverflow.com/questions/5461702/regex-to-find-url-in-a-text
-
是的,正则表达式会做到这一点。我可以在 php 中做到这一点,但不能在 jquery 中做到这一点? preg_replace('!(http://[a-z0-9_./?=&-]+)!i', '$1 ', $text." ") ;
标签: javascript jquery html regex replace