question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-useless-escape inside `new RegExp`

See original GitHub issue

What version of ESLint are you using? v2.9.0 What parser (default, Babel-ESLint, etc.) are you using? standard Please show your full configuration:

      "ecmaVersion": 6,
      "extends": "standard",
      "installedESLint": true,
      "plugins": [
        "standard"
      ],
      "env": {
        "node": true,
        "browser": true
      },
      "rules": {
        "comma-style": [
          "error"
          , "first"
        ]
        , "one-var": ["error", {
          "var": "always",
          "let": "always",
          "const": "always"
        }]
        , "space-before-function-paren": ["error",
          {"anonymous": "always", "named": "never"}]
      }

What did you do? Please include the actual source code causing the issue.

`new RegExp('[^@]+@[^@]+\.[^@]+')`

What did you expect to happen? Do not get any warnings or error.

What actually happened? Please include the actual, raw output from ESLint. ESLint: Unnecessary escape character: \. (no-useless-escape)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
zhenyabcommented, May 12, 2016

@michaelficarra This regex to check e-mail and I want really escape the . because I want to check that . (dot) is exists inside the string. If I use the alternate syntax of regex like so:

/[^@]+@[^@]+\.[^@]+/

then I do not get this warning.

3reactions
ratracegradcommented, Aug 8, 2017

I am using the RegExp to validate email addresses from http://emailregex.com/ which is

/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

this generates two no-useless-escape errors. Any suggestion on how to overcome this without removing this warning in the eslintrc file?

(edited by @not-an-aardvark to add a code block)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Unnecessary escape character: \/ no-useless-escape
Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.
Read more >
regexp/no-useless-escape
This rule reports unnecessary escape characters in RegExp. You may be able to find another mistake by finding unnecessary escapes.
Read more >
Escaping, special characters - The Modern JavaScript Tutorial
If we are creating a regular expression with new RegExp , then we don't have to escape / , but need to do...
Read more >
Improve Readability with ES6 Template Strings
Yay, no more backslash \ to escape characters in strings! A better way is to use template strings with backticks ( ` )....
Read more >
ValidateJavaScript - Online Tool to Find & Fix JavaScript Errors
new -cap new-parens newline-after-var newline-before-return newline-per-chained-call no-alert ... no-inner-declarations no-invalid-regexp no-invalid-this
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found