Mutation Person
Mutation Person

Reputation: 30498

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

JSLint is reporting a 'Bad Escapement' error on the following code that I am reviewing.

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?

Upvotes: 0

Views: 597

Answers (2)

codeandcloud
codeandcloud

Reputation: 55200

Bad escapement is an ADsafe Violation

Upvotes: 0

Skilldrick
Skilldrick

Reputation: 70819

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.

Upvotes: 2

Related Questions