1 # disallow invalid regular expression strings in `RegExp` constructors (no-invalid-regexp)
3 An invalid pattern in a regular expression literal is a `SyntaxError` when the code is parsed, but an invalid string in `RegExp` constructors throws a `SyntaxError` only when the code is executed.
7 This rule disallows invalid regular expression strings in `RegExp` constructors.
9 Examples of **incorrect** code for this rule:
12 /*eslint no-invalid-regexp: "error"*/
21 Examples of **correct** code for this rule:
24 /*eslint no-invalid-regexp: "error"*/
33 Please note that this rule validates regular expressions per the latest ECMAScript specification, regardless of your parser settings.
35 If you want to allow additional constructor flags for any reason, you can specify them using the `allowConstructorFlags` option. These flags will then be ignored by the rule.
39 This rule has an object option for exceptions:
41 * `"allowConstructorFlags"` is an array of flags
43 ### allowConstructorFlags
45 Examples of **correct** code for this rule with the `{ "allowConstructorFlags": ["a", "z"] }` option:
48 /*eslint no-invalid-regexp: ["error", { "allowConstructorFlags": ["a", "z"] }]*/
57 * [Annotated ES5 ยง7.8.5 - Regular Expression Literals](https://es5.github.io/#x7.8.5)