Skip to content

regexEmptyGroups

Reports empty groups in regular expressions.

✅ This rule is included in the ts logical presets.

Reports empty capturing and non-capturing groups in regular expressions. Empty groups like () or (?:) match the empty string and have no meaningful effect on the regex pattern. This rule reports those empty groups.

const pattern = /()/;
const pattern = /(?:)/;
const pattern = /(|)/;
const pattern = new RegExp("()");

This rule is not configurable.

If you are intentionally using empty groups for some specific purpose in generated or legacy code, such as for stylistic separations, you might prefer to disable this rule. You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.

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