Disallow Invalid Regular Expressions (no-invalid-regexp)

This rule validates string arguments passed to the RegExp constructor.

Rule Details

The following patterns are considered warnings:

RegExp('['])
RegExp('.', 'z') // invalid flags
new RegExp('\\')

The following patterns are not considered warnings:

RegExp('.')
new RegExp
this.RegExp('[')

New ECMAScript 6 Flags

ECMAScript 6 adds the “u” (unicode) and “y” (sticky) flags. You can enable these to be recognized as valid by adding the following to your .eslintrc file:

"ecmaFeatures": {
  "regexYFlag": true,
  "regexUFlag": true
}

Further Reading

Version

This rule was introduced in ESLint 0.1.4.

Resources