Why does JSLint report 'bad escapement' on this code?
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
精彩评论