Skip to content

regexEmptyCapturingGroups

Reports capturing groups that only capture empty strings.

✅ This rule is included in the ts logical and logicalStrict presets.

Reports capturing groups in regular expressions that can only capture zero-length strings. A capturing group that never captures any text is likely a mistake or unnecessary.

A capturing group with no content.

const pattern = /()/;

Assertions match positions, not characters, so a capturing group containing only assertions captures nothing.

const pattern = /(\b)/;

A quantifier with min=0 like * or ? applied to all elements means the group can match zero characters.

const pattern = /(a*)/;

The rule also checks regex patterns in RegExp constructor calls.

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

This rule is not configurable.

If you intentionally use empty capturing groups for indexing purposes or other as a stylistic choice, you might prefer to disable this rule.

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