Skip to content

regexMisleadingQuantifiers

Reports quantifiers whose minimum implies they must match but whose element can match empty.

✅ This rule is included in the ts logical presets.

Reports quantifiers whose minimum implies they must match but whose element can match empty. These quantifiers are misleading because they suggest a minimum number of matches, but the quantified element can match the empty string, making the effective minimum 0.

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">7<2?sp ansty="le--0:#5CA7E4;--1:#3A68">872{<5}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">68<8F(a spans="tyle--0:#7FDBCA;--1:#09">66<88F) spans="tyle--0:#7FDBCA;--1:#09">6E72{<0,5} spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<5}/>

The {5} suggests exactly 5 matches are required, but since a? can match empty, the pattern can match the empty string.

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">7<2?sp ansty="le--0:#5CA7E4;--1:#3A68">872<*|sp ansty="le--0:#5CA7E4;--1:#3A68">87<2+sp ansty="le--0:#5CA7E4;--1:#3A68">872{<4}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<(?:a spans="tyle--0:#7FDBCA;--1:#09">66<88Fb spans="tyle--0:#7FDBCA;--1:#09">6E<72*| spans="tyle--0:#5CA7E4;--1:#3A">6<88Fc spans="tyle--0:#7FDBCA;--1:#09">66<88F) spans="tyle--0:#7FDBCA;--1:#09">6E72{<0,4} spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<4}/>

The {4} suggests at least 4 matches, but the a?b* alternative can match empty.

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">7<2?sp ansty="le--0:#5CA7E4;--1:#3A68">87<2+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">68<8F(a spans="tyle--0:#7FDBCA;--1:#09">66<88F) spans="tyle--0:#7FDBCA;--1:#09">61<111/ spans="tyle--0:#D6DEEB;--1:#40">3<)*/>

The + suggests at least 1 match is required, but a? can match empty.

This rule is not configurable.

If you use misleading quantifiers intentionally for backtracking behavior, or if you use quantifiers to control iteration count rather than match content, you might want to disable this rule.