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">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8Faaa1/sp>1<1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">6111/><88Fa spans="tyle--0:#7FDBCA;--1:#09">6E788Fa><2{5} spans="tyle--0:#D9F5DD;--1:#11">12{5}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><5}/>5}/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0\d\d\d\d1/sp><\dsp ansty="le--0:#D9F5DD;--1:#1111">1\dsp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#82AAFF;--1:#3B">61111/>6E7<2{5} spans="tyle--0:#D9F5DD;--1:#11">12{5}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><5}/>5}/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[a-z][a-z][a-z][a-z][a-1/sp>1<1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[111/>6E7<2{5} spans="tyle--0:#D9F5DD;--1:#11">12{5}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><5}/>5}/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0...1/sp><..sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#82AAFF;--1:#3B">6111/><1B0. spans="tyle--0:#7FDBCA;--1:#09">6E71B0.><2{5} spans="tyle--0:#D9F5DD;--1:#11">12{5}><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><5}/>5}/>
AEconsB0patteAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>AB0RegE5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Daaa1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meco"><);d>);d>);d> 44AEco61B0pat44A6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Re4AE >31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name"><}")>}")>53)>
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.