Skip to content

regexRepeatQuantifiers

Reports consecutive identical elements in regular expressions that should use quantifiers.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Matching multiple consecutive characters in a regular expression can be done either by writing out that character repeatedly or using a quantifier. Quantifiers keep the regex shorter and harder to miscount, and they make it obvious how many times a part repeats without visually scanning a long run of characters. For example, writing a{5} is more concise and readable than aaaaa.

This rule reports runs of five or more identical elements in regular expressions and suggests replacing them with quantifiers.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8Faaa1<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">6E7<2{5} spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<5}/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0\d\d\d\d<\dsp 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">616E7<2{5} spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<5}/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[a-z][a-z][a-z][a-z][a-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[6E7<2{5} spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<5}/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0...<..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">6<1B0. spans="tyle--0:#7FDBCA;--1:#09">6E7<2{5} spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<5}/>
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">4Daaa1<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">4E4D1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><}")>

This rule is not configurable.

If your project has a style guide that prefers explicit repetition for clarity, or if you are programmatically generating regular expressions where repetition is easier to produce, you might want to disable this rule.