Skip to content

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.

Invalid Pattern

const pattern = RegExp("(");
const pattern = RegExp("abc", "q");
const pattern = RegExp("abc", "gg");
const pattern = RegExp("abc", "uv");

This rule is not configurable.

If you are working in an environment with different regular expression semantics than the norm, you may prefer to disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.