no-invalid-regexp
Configuration
rslint.config.ts
Rule Details
Disallows invalid regular expression strings in RegExp constructors. This rule validates patterns and flags passed to new RegExp(pattern, flags) and RegExp(pattern, flags) when the arguments are string literals.
Valid flags are: d, g, i, m, s, u, v, y.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
allowConstructorFlags
An array or string of additional flags to allow in RegExp constructors. For example, to allow the a and z flags:
Known Limitations
The following ECMAScript regex features are not yet fully supported in pattern validation:
- Unicode property long names (
\p{Letter}) andScript=syntax (\p{Script=Latin}) v-flag set notation ([A--B],[A&&B],[A--[0-9]])- Surrogate pair named capture groups (
(?<\ud835\udc9c>.)) - Invalid escape detection in unicode mode (
\awithuflag) v-flag specific parsing ([[]withvflag)- Duplicate named capture groups outside alternatives (
(?<k>a)(?<k>b)) - Inline modifier validation (
(?ii:foo),(?-:foo),(?-u:foo))
Flag validation (invalid flags, duplicate flags, u/v conflict) and allowConstructorFlags are fully aligned with ESLint.