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.

AEconsB0patteAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F<()sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6881<111/ spans="tyle--0:#D6DEEB;--1:#40">3

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

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8AE<\bsp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#C792EA;--1:#88">441<111/ spans="tyle--0:#D6DEEB;--1:#40">3<\b/>

A quantifier that never repeats its content, such as {0}, means the group captures nothing.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F<(asp ansty="le--0:#7FDBCA;--1:#096E">72{<0}sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">68<8F(a spans="tyle--0:#7FDBCA;--1:#09">66<88F) spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<*)/>

The rule also checks regex patterns in RegExp constructor calls.

AEconsB0patteAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0RegE5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D<()sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEco61B0pat44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Re31<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><)")>

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.