Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.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/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 SublimeLineter-jshint警告关于;“不必要的逃避”;在正则表达式字符串中_Javascript_Regex_Jshint - Fatal编程技术网

Javascript SublimeLineter-jshint警告关于;“不必要的逃避”;在正则表达式字符串中

Javascript SublimeLineter-jshint警告关于;“不必要的逃避”;在正则表达式字符串中,javascript,regex,jshint,Javascript,Regex,Jshint,jsHint显示错误的警告: 不好的或不必要的逃跑 “\:”和“。” 对于正则表达式,上面的转义是必需的。我怎样才能让林特原谅这件事 谢谢 如果确实要匹配,则需要在RegExp构造函数中使用双反斜杠来转义,如下所示 return new RegExp('^https\://wtinbox\.worktile\.com/(.*)$'); console.log(new RegExp("\.").test("a")); # true console.log(new RegE

jsHint显示错误的警告:

不好的或不必要的逃跑 “\:”和“。”

对于正则表达式,上面的转义是必需的。我怎样才能让林特原谅这件事


谢谢

如果确实要匹配
,则需要在
RegExp
构造函数中使用双反斜杠来转义
,如下所示

            return new RegExp('^https\://wtinbox\.worktile\.com/(.*)$');
console.log(new RegExp("\.").test("a"));
# true
console.log(new RegExp("\\.").test("."));
# true
console.log(new RegExp("\\.").test("a"));
# false
此外,您不需要在正则表达式中转义
,因为它没有特殊含义

最好使用RegEx-literal,如下所示

            return new RegExp('^https\://wtinbox\.worktile\.com/(.*)$');
console.log(new RegExp("\.").test("a"));
# true
console.log(new RegExp("\\.").test("."));
# true
console.log(new RegExp("\\.").test("a"));
# false

如果确实要匹配
,则需要在
RegExp
构造函数中使用双反斜杠来转义
,如下所示

            return new RegExp('^https\://wtinbox\.worktile\.com/(.*)$');
console.log(new RegExp("\.").test("a"));
# true
console.log(new RegExp("\\.").test("."));
# true
console.log(new RegExp("\\.").test("a"));
# false
此外,您不需要在正则表达式中转义
,因为它没有特殊含义

最好使用RegEx-literal,如下所示

            return new RegExp('^https\://wtinbox\.worktile\.com/(.*)$');
console.log(new RegExp("\.").test("a"));
# true
console.log(new RegExp("\\.").test("."));
# true
console.log(new RegExp("\\.").test("a"));
# false

“jsHint显示错误的警告”不,它没有<代码>“\:”与
“:”
相同。同样适用于
“\.
。这些不是有效的转义序列,因此JavaScript只会将它们解析为字符本身。“上面的转义对正则表达式来说是必要的。”但你不是在转义正则表达式中的字符,而是在字符串中转义。Felix,这正是我的错误。非常感谢。“jsHint显示错误的警告”不,它没有<代码>“\:”与
“:”
相同。同样适用于
“\.
。这些不是有效的转义序列,因此JavaScript只会将它们解析为字符本身。“上面的转义对正则表达式来说是必要的。”但你不是在转义正则表达式中的字符,而是在字符串中转义。Felix,这正是我的错误。非常感谢。