Skip to content

regexEmptyCharacterClasses

Reports character classes that match no characters.

✅ This rule is included in the ts logical presets.

Reports empty character classes in regular expressions. An empty character class [] matches nothing and always fails, which is usually a mistake.

An empty character class matches nothing.

const pattern = /[]/;

An empty character class in a larger pattern causes the entire match to fail.

const pattern = /a[]b/;

The rule also checks regex patterns in RegExp constructor calls.

const pattern = new RegExp("[]");

A negated empty character class [^] matches any character and is valid.

const pattern = /[^]/;

This rule is not configurable.

If you intentionally use empty character classes as a way to create a pattern that never matches (e.g., for testing purposes), you might prefer to disable this rule.

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