regexValidity
Reports invalid regular expressions.
✅ This rule is included in the ts logical presets.
It is possible to write regular expression literals that will throw at runtime. This includes invalid patterns, invalid flags, duplicate flags, and conflicting flag combinations. This rule reports those invalid regular expressions.
Examples
Section titled “Examples”Invalid Pattern
const pattern = RegExp("(");const pattern = RegExp("abc", "q");const pattern = RegExp("abc", "gg");const pattern = RegExp("abc", "uv");const pattern = RegExp("(abc)");const pattern = RegExp("abc", "g");const pattern = RegExp("abc", "gi");const pattern = RegExp("abc", "u");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you are working in an environment with different regular expression semantics than the norm, you may prefer to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Deno:
no-invalid-regexp - ESLint:
no-invalid-regexpregexp/no-invalid-regexp - Oxlint:
eslint/no-invalid-regexp
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.