Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unnecessary Escape warning

Tyler Breisacher edited this page Mar 10, 2017 · 2 revisions

What's up with this "Unnecessary escape" warning?

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. See this jsfiddle link for a demo.

In some cases, it might be much simpler to write your code using a /RegExp literal/ instead of a 'string literal' to remove the need for a lot of backslashes.

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.