Skip to content

regexZeroQuantifiers

Reports quantifiers with a maximum of zero, which are useless.

✅ This rule is included in the ts logical presets.

Reports quantifiers with a maximum of zero ({0} or {0,0}), which are useless because they match zero occurrences (the empty string). A quantifier with a maximum of 0 means the quantified element will never be matched, so both the quantifier and its element can be removed.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">872{<0}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">6<88Fa spans="tyle--0:#7FDBCA;--1:#09">61<111/ spans="tyle--0:#D6DEEB;--1:#40">3

The {0} quantifier means a will never be matched, making the entire quantified expression useless.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">872{0,<0}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">6<88Fa spans="tyle--0:#7FDBCA;--1:#09">6E72{<0,1} spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<1}/>

The {0,0} quantifier also means exactly zero matches, making it equivalent to an empty match.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(a72{<0}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">688F<(ab) spans="tyle--0:#7FDBCA;--1:#09">61<111/ spans="tyle--0:#D6DEEB;--1:#40">3<)?/>

The group (ab) with {0} will never match anything useful.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[a-72{<0}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:#82AAFF;--1:#3B">61B0[61<111/ spans="tyle--0:#D6DEEB;--1:#40">3<]*/>

The character class [a-z] with {0} will never match any character.

This rule is not configurable.

There is no valid use case for a quantifier with a maximum of 0, so this rule should generally always be enabled.