regexEmptyGroups
Reports empty groups in regular expressions.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
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”44AEcoEmpty Non-Capturing Group
Section titled “Empty Non-Capturing Group”44AEcoEmpty Group with Empty Alternatives
Section titled “Empty Group with Empty Alternatives”44AEcoRegExp Constructor
Section titled “RegExp Constructor”44AEcoOptions
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
