Skip to content

regexLookaroundQuantifierOptimizations

Reports non-constant quantifiers in lookaround assertions that could be simplified.

✅ This rule is included in the ts logical presets.

Reports non-constant quantifiers in lookaround assertions that could be simplified. Lookahead and lookbehind assertions only check whether a pattern matches, not how much text it consumes. Non-constant quantifiers at the end of lookaheads or start of lookbehinds can be replaced with their minimum.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(?=7<2*sp ansty="le--0:#5CA7E4;--1:#3A68">81<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(1<111/ spans="tyle--0:#D6DEEB;--1:#40">3
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(?=7<2+sp ansty="le--0:#5CA7E4;--1:#3A68">81<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(?<=ba) spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3
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">72{4,<9}sp ansty="le--0:#5CA7E4;--1:#3A68">81<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">6E7<2{4} spans="tyle--0:#5CA7E4;--1:#3A">6<88F) spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<})/>

Lookbehinds match from right to left, so non-constant quantifiers at the start are problematic.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(?<<=sp ansty="le--0:#82AAFF;--1:#3B61">B0[a-7<2*sp ansty="le--0:#5CA7E4;--1:#3A68">81<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(1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<=)/>

This rule is not configurable.

If you are intentionally using non-constant quantifiers in lookarounds for documentation purposes or if you are building patterns dynamically, you might want to disable this rule.