Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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中反斜杠的RegExr超出范围_Javascript_Regex - Fatal编程技术网

javascript中反斜杠的RegExr超出范围

javascript中反斜杠的RegExr超出范围,javascript,regex,Javascript,Regex,我使用\(bakcslash)进行regExr匹配时出现超出范围的错误。。解决方案请 if ($('.channelquickvalidte').val().match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/<>\\]+$") == null) /* Error... */ { alert("Character between A-Z/a-z and 0-9 are allowed. Additional you can use \"''

我使用\(bakcslash)进行regExr匹配时出现超出范围的错误。。解决方案请

 if ($('.channelquickvalidte').val().match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/<>\\]+$") == null)  /* Error... */

{ alert("Character between A-Z/a-z and 0-9 are allowed. Additional you can use \"''@+&,._$!#%^*()_+=<>/\\\" character"); // its working fine

不要将反斜杠放在char类的末尾,请使用:

match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/\\<>]+$")
match(“^[a-zA-Z\s0-9,@+&$,.\\\\%^*()。+=/\\]+$”)

match(“^[a-zA-Z\s0-9,@+&$,.\\\\%^*()。+=/\\\]+$”)
您可以将其简化为:

match("^[\w\s,'@+&$,.!#%^*()+=/\\<>]+$")
match(“^[\w\s,@+&$,.!\%^*()+=/\\]+$”)
\w
通常代表
[a-zA-Z0-9\
,但它取决于语言环境。

\s
代表任何空格字符,即
[\t\r\n\f]
,因此您不需要在car类中增加空格

如果您的character类中也有“`”,为什么还要在字符类中添加
\s
?尝试删除
\s
或将其移动到其他位置。我可以想象,js以某种奇怪的方式解释
\s0
,从而产生错误。
match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/<>\\\\]+$")
match("^[\w\s,'@+&$,.!#%^*()+=/\\<>]+$")