Skip to content

regexCharacterClassRanges

Reports character class elements that can be simplified to ranges.

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

Character class ranges in regular expressions are more concise than listing individual consecutive characters. When four or more consecutive characters appear in a character class, they can be combined into a range for better readability.

AEconsB0letteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[abc1<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">AEconsB0digiAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[012<3]sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">AEconsB0uppercaAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[ABC1<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">AEconsB0mixedWithRanAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[a-c1<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">
44AEco61B0let446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">44AEco61B0di446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[<0-3] spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<3]/><;di vdivclass="Nameexpressive-">44AEco61B0upper446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">6376// Three consecutive characters are allowed (below the thresh44AEco61B0s446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">6376// Non-consecutive characters cannot be simpli44AEco61B0vo446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[ae1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">6376// Existing ranges are already opt44AEco61B0allLet446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[1<111/ spans="tyle--0:#D6DEEB;--1:#40">3

This rule is not configurable.

If you prefer listing individual characters for clarity (for example, when the characters represent specific values rather than a range), you might prefer to disable this rule. Some developers find explicit character lists easier to understand when the character set represents distinct concepts.