正则表达式查找以文本而不是链接形式编写的 URL

regex to find urls written as text and not links

本文关键字:URL 链接 查找 文本 正则表达式      更新时间:2023-09-26

我可以有长文本,可以包含以下任一内容:

http://desktop.com/

<a href="http://desktop.com/" target="_blank" data-mce-href="http://desktop.com">http://desktop.com</a>

我的问题是我需要获取所有当前不存在的独立 URL 使用正则表达式的链接,然后我将独立 URL 更改为链接。

另外,另一点是链接可以出现在文本中的任何位置,在一行的开头/中间/结尾。

这是您问题的一个例子:-)

http://www.codesheet.org/codesheet/u9iMMlpq

var tweet ="一些带有网站链接的 tweek:http://www.codesheet.org/";var pattern =/(HTTP:''/''/|HTTPS:''/''/)([a-zA-Z0-9.''/&?_=!*,''('')+-]+)/i;var 替换 = "$1$2";tweet = tweet.replace(pattern , replace);document.write(tweet);