Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 Regex查找不遵循http://或https的网站名称://_Javascript_Regex_Regex Group - Fatal编程技术网

Javascript Regex查找不遵循http://或https的网站名称://

Javascript Regex查找不遵循http://或https的网站名称://,javascript,regex,regex-group,Javascript,Regex,Regex Group,我需要找到regex来查找不遵循http://或https://的网站名称 乙二醇 URL也可以是更大字符串的一部分,如 <p><a href="https://www.w3schools.com/html/">www.w3schools.com</a></p> 其中,第二个示例中的www.w3schools.com和www.abc.com应该匹配,并且字符串中可以有多个URL 提前感谢如果您只想排除以http://或https://开头的字符串

我需要找到regex来查找不遵循http://或https://的网站名称 乙二醇

URL也可以是更大字符串的一部分,如

<p><a href="https://www.w3schools.com/html/">www.w3schools.com</a></p>
其中,第二个示例中的www.w3schools.com和www.abc.com应该匹配,并且字符串中可以有多个URL

提前感谢

如果您只想排除以http://或https://开头的字符串,那么使用负前瞻就足够容易了:

var match=www.google.co.in; var nomatch=http://www.google.co.in; var re=new RegExp^?!https?:\/\/.*$; 如果重新测试匹配{ console.logmatch+有效; } 如果re.testnomatch{ console.lognomatch+有效;
} 可以使用正则表达式^http | https://获取包含http://或https://的字符串的匹配项。然后,当您应用匹配时,请使用not!运算符将匹配反转为不包含http://或https://:

var regEx=new RegExp^http | https://,i; var str=http://www.google.co.in; 变量匹配=!regEx.teststr; console.logmatch+'表示'+str; str='http://www.google.co.in'; 匹配=!regEx.teststr; console.logmatch+'表示'+str; str='www.google.co.in'; 匹配=!regEx.teststr; console.logmatch+'表示'+str 你需要吗

/(?<!https:\/\/)(?<!http:\/\/)(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)((?=[^\w.\/-]+?)|$)+/ig
现在,即使是对于www.google.de:

([^\/]{2,2}|^)(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)(([^\w.\/-]+?)|$)+
你可以这样替换

我将“www…”替换为“Test”

/([^\/]{2,2}|^)(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)(([^\w.\/-]+?)|$)+/$1Test$4/gi
我用IntelliJ的正则表达式工具进行了测试

我的意见是:

<p><a href="https://www.w3schools.com/html/"><a href="http://www.w3schools.com/html/">www.w3schools.com</a></p>
<p><a href="https://www.google.com/html/"><a href="http://www.google.com/html/">www.google.com</a>
结果是:

<p><a href="https://www.w3schools.com/html/"><a href="http://www.w3schools.com/html/">Test</a></p>
<p><a href="https://www.google.com/html/"><a href="http://www.google.com/html/">Test</a>

如果有帮助的话,如果你投票赞成,那就太好了:-

不要用正则表达式字符串来解析HTML不是HTML,只是举个例子,相应地更新了问题,谢谢上面的链接正则表达式在javascript中不起作用,当运行我得到一个错误Syntaxer:无效的正则表达式:/?^!https://?@biff:添加了另一种可能来检查它。您好,这很有帮助,但是如果字符串只是www.google.com,rejex将不会捕获它,它也会捕获像www.google.com这样的字符串,这是错误的,您可以吗help@biff:修改它:-
/([^\/]{2,2}|^)(www\.[\w-.]*?[\w-]+?(\/[\w-]*?)*?)(([^\w.\/-]+?)|$)+/$1Test$4/gi
<p><a href="https://www.w3schools.com/html/"><a href="http://www.w3schools.com/html/">www.w3schools.com</a></p>
<p><a href="https://www.google.com/html/"><a href="http://www.google.com/html/">www.google.com</a>
<p><a href="https://www.w3schools.com/html/"><a href="http://www.w3schools.com/html/">Test</a></p>
<p><a href="https://www.google.com/html/"><a href="http://www.google.com/html/">Test</a>