Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Regex 正则表达式检查url不起作用_Regex - Fatal编程技术网

Regex 正则表达式检查url不起作用

Regex 正则表达式检查url不起作用,regex,Regex,我在下面添加了正则表达式以检查它是否为url: function checkurl(url){ var regex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/; if(!$.trim(url).match(regex)){ //alert("Not Valid Url"); alert('Not Valid Url'); return false; } 这适

我在下面添加了正则表达式以检查它是否为url:

function checkurl(url){
var regex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
if(!$.trim(url).match(regex)){
        //alert("Not Valid Url");
        alert('Not Valid Url');
        return false;
}
这适用于大多数url,但对于以下url则显示错误:


您需要在最后一个字符类中添加几个字符以支持查询字符串,即
=

^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([?=&\/\w \.-]*)*\/?$

您需要在最后一个字符类中添加几个字符以支持查询字符串,即
=

^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([?=&\/\w \.-]*)*\/?$

尝试此操作。请参阅演示。将
?=
添加到字符类。还删除了
*)*
,这将导致灾难性的回溯

尝试此操作。请参阅演示。将
?=
添加到字符类。还删除了
*)*
,这将导致灾难性的回溯


它不适用于该URL,因为它有一个查询字符串(
?v=wEQi87xSIgU

将此添加到
$
之前:

(\?[^#]*)?(#.*)?

这将匹配查询字符串和散列。

它不适用于该URL,因为它有一个查询字符串(
?v=wEQi87xSIgU

将此添加到
$
之前:

(\?[^#]*)?(#.*)?

这将匹配查询字符串和散列。

很好地指出了错误!按OPs模式+提供的示例url计算:S@SatishKumarSingh它会让所有人受益。它失败了吗?很好地指出了问题所在!按OPs模式+提供的示例url计算:S@SatishKumarSingh它将为所有人工作。它失败了吗?