Skip to content

regexEmptyGroups

Reports empty groups in regular expressions.

✅ This rule is included in the ts logical and logicalStrict 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
const pattern: RegExp
pattern
= /()/;
const
const pattern: RegExp
pattern
= /(?:)/;
const
const pattern: RegExp
pattern
= /(|)/;
const
const pattern: RegExp
pattern
= new
var RegExp: RegExpConstructor
new (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
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 ❤️‍🔥 around the world by the Flint team and contributors.