Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正则表达式查找以文本而非链接形式写入的URL_Javascript_Regex - Fatal编程技术网

Javascript 正则表达式查找以文本而非链接形式写入的URL

Javascript 正则表达式查找以文本而非链接形式写入的URL,javascript,regex,Javascript,Regex,我可以有长文本,其中可以包含以下内容之一: http://desktop.com/ 及 我的问题是,我需要使用正则表达式获取当前不存在于链接中的所有独立URL,因为我将把独立URL更改为链接 另外,还有一点是,链接可以出现在文本中的任何位置,在一行的开始/中间/结束处。以下是您的问题示例:-) var tweet=“一些有网站链接的tweek:http://www.codesheet.org/"; 变量模式=/(HTTP:\/\/\/;HTTPS:\/\/)([a-zA-Z0-9.\/&

我可以有长文本,其中可以包含以下内容之一:

http://desktop.com/


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


另外,还有一点是,链接可以出现在文本中的任何位置,在一行的开始/中间/结束处。

以下是您的问题示例:-)

var tweet=“一些有网站链接的tweek:http://www.codesheet.org/"; 变量模式=/(HTTP:\/\/\/;HTTPS:\/\/)([a-zA-Z0-9.\/&?\/=!*,\(\)+-]+)/i; var replace=“$1$2”; tweet=tweet.replace(模式,replace); 写文件(tweet);
Reg Exp with HTML:请阅读以下内容:基本上,您需要在元素上循环,并检查它们的文本是否包含链接。这还将在需要避免的第二种字符串中找到URL。
<a href="http://desktop.com/" target="_blank" data-mce-href="http://desktop.com">http://desktop.com</a>
var tweet = "Some tweek with a link to a site: http://www.codesheet.org/"; var pattern = /(HTTP:\/\/|HTTPS:\/\/)([a-zA-Z0-9.\/&?_=!*,\(\)+-]+)/i; var replace = "$1$2"; tweet = tweet.replace(pattern , replace); document.write(tweet);