开发者

Why does JSLint report 'bad escapement' on this code?

开发者 https://www.devze.com 2023-02-04 09:03 出处:网络
JSLint is reporting a \'Bad Escapement\' error on the following code that I am revi开发者_如何学运维ewing.

JSLint is reporting a 'Bad Escapement' error on the following code that I am revi开发者_如何学运维ewing.

var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

var validChars = "\[^\\s" + specialChars + "\]";  //<---JSLint 'Bad Escapement'

Would anyone be able to shed any light on this, and to how it might be resolved?


If you want to put a literal backslash in a string literal you need to double it:

var validChars = "\\[^\\\\s" + specialChars + "\\]"; 

If you're making regexes, it's much easier to use regex literals.


Bad escapement is an ADsafe Violation

0

精彩评论

暂无评论...
验证码 换一张
取 消