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.
Examples
Section titled “Examples”Empty Capturing Group
Section titled “Empty Capturing Group”const pattern = /()/;const pattern = /(a)/;Empty Non-Capturing Group
Section titled “Empty Non-Capturing Group”const pattern = /(?:)/;const pattern = /(?:a)/;Empty Group with Empty Alternatives
Section titled “Empty Group with Empty Alternatives”const pattern = /(|)/;const pattern = /(a|)/;RegExp Constructor
Section titled “RegExp Constructor”const pattern = new RegExp("()");const pattern = new RegExp("(a)");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-empty-group
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.