Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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中不起作用_Javascript_Regex_Angularjs_Match_String Matching - Fatal编程技术网

正则表达式在JavaScript中不起作用

正则表达式在JavaScript中不起作用,javascript,regex,angularjs,match,string-matching,Javascript,Regex,Angularjs,Match,String Matching,我有一个正则表达式的问题,我在一些网站上测试过,它正在工作,但当我在项目中使用正则表达式时,它与正确的结果不匹配。正则表达式如下所示 ^(http|https)\://(www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$ var pattern = new RegExp(URL_REGEXP); if (pattern.test($('inp

我有一个正则表达式的问题,我在一些网站上测试过,它正在工作,但当我在项目中使用正则表达式时,它与正确的结果不匹配。正则表达式如下所示

^(http|https)\://(www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$
var pattern = new RegExp(URL_REGEXP);
if (pattern.test($('input.editValueText').val()))
我需要这种正则表达式,因为我需要验证类似的东西:

http://www.test.com
https://www.test.com/login
我使用的代码如下

^(http|https)\://(www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$
var pattern = new RegExp(URL_REGEXP);
if (pattern.test($('input.editValueText').val()))

您忘记在最后一个字符类之后添加
+
。你的正则表达式是

^(http|https):\/\/(www\.)[a-zA-Z0-9-.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9])?\/?([a-zA-Z0-9-._\?\,\'\/\+&%\$#\=~]+)*$

答案可能是重复的,谢谢兄弟。我花了一个多小时寻找问题所在。非常感谢你的回答