Reports trivially nested quantifiers in regular expressions that can be simplified.
✅ This rule is included in the ts logical presets.
When a non-capturing group contains a single quantified element and the group itself is quantified, the nested quantifiers can often be combined into a single quantifier.
This rule reports trivially nested quantifiers in regular expressions that can be simplified.
(?:a?)+ can be simplified to a* because an optional element repeated one or more times is equivalent to zero or more.
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(?1/sp><:asp ansty="le--0:#7FDBCA;--1:#096E">7<2?sp ansty="le--0:#5CA7E4;--1:#3A68">82?sp>7<2+sp ansty="le--0:#D9F5DD;--1:#1111">12+sp><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">688Fa>1<111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>
(?:a+)+ can be simplified to a+ because one or more of one or more is still one or more.
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(?1/sp><:asp ansty="le--0:#7FDBCA;--1:#096E">7<2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>7<2+sp ansty="le--0:#D9F5DD;--1:#1111">12+sp><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">688Fa>1<111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>
(?:a+)* can be simplified to a* because one or more repeated zero or more times is zero or more.
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(?1/sp><:asp ansty="le--0:#7FDBCA;--1:#096E">7<2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>7<2*sp ansty="le--0:#D9F5DD;--1:#1111">12*sp><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">688Fa>1<111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>
The rule also works with character classes and escape sequences.
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(1/sp>B0[a-?:sp>7<2?sp ansty="le--0:#5CA7E4;--1:#3A68">82?sp>7<2+sp ansty="le--0:#D9F5DD;--1:#1111">12+sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meec-li">AEconsB0digiAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(1/sp>B0?:sp><\dsp ansty="le--0:#7FDBCA;--1:#096E">7\dsp><2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>7<2+sp ansty="le--0:#D9F5DD;--1:#1111">12+sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp>3;d><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/>61<111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>44AEco61B0di446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#82AAFF;--1:#3B">61111/>61<111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>
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">4D(?:a?1"sp><)+sp ansty="le--0:#D9F5DD;--1:#1111">1)+sp><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">4E111"><4Da* spans="tyle--0:#D9F5DD;--1:#11">14Da*><111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name"><*")>*")>53)>
This rule is not configurable.
If you prefer to keep the nested structure for readability or documentation purposes, or if you need the specific behavior of the non-capturing group for replacement operations, you might prefer to disable this rule.
You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.