-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Unnecessary Escape warning
Tyler Breisacher edited this page Mar 10, 2017
·
2 revisions
If you're writing a string intended to be used as a regular expression you likely have special RegExp escapes in it, such as \s
or \w
. You may see a warning saying something like "Unnecessary escape: '\w' is equivalent to just 'w'". This is because, while \w
is a valid escape sequence in regular expressions, it isn't in string literals. In a string literal, \w
just means w
. To get the RegExp escape \w
you need \\w
. Or if possible, just write your code as a /RegExp literal/
instead of a 'string literal'
which will remove the need for a lot of backslashes.