Disallow Invalid Regular Expressions (no-invalid-regexp)

This rule validates string arguments passed to the RegExp constructor.

Rule Details

The following patterns are considered problems:

/*eslint no-invalid-regexp: 2*/

RegExp('[')      /*error Invalid regular expression: /[/: Unterminated character class*/

RegExp('.', 'z') /*error Invalid flags supplied to RegExp constructor 'z'*/

new RegExp('\\') /*error Invalid regular expression: /\/: \ at end of pattern*/

The following patterns are not considered problems:

/*eslint no-invalid-regexp: 2*/


new 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 setting the ECMAScript version to 6 in your ESLint configuration.

Further Reading


This rule was introduced in ESLint 0.1.4.