Skip to content

regexConciseCharacterClassNegations

Reports negated character classes that can use shorthand escapes.

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

Enforces using shorthand escape sequences like \D, \W, \S, and \P instead of negated character classes. For example, [^\d] can be written more concisely as \D.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#7FDBCA;--1:#096E">7<2^sp ansty="le--0:#82AAFF;--1:#3B61">B0\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">611<111/ spans="tyle--0:#D6DEEB;--1:#40">3<\D/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#7FDBCA;--1:#096E">7<2^sp ansty="le--0:#82AAFF;--1:#3B61">B0\7<2+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">6161<111/ spans="tyle--0:#D6DEEB;--1:#40">3
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#7FDBCA;--1:#096E">7<2^sp ansty="le--0:#82AAFF;--1:#3B61">B0\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">611<111/ spans="tyle--0:#D6DEEB;--1:#40">3<\S/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#7FDBCA;--1:#096E">7<2^sp ansty="le--0:#F78C6C;--1:#AA09">82<\psp ansty="le--0:#82AAFF;--1:#3B61">B0{Letter<}]sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#F78C6C;--1:#AA">09<82\P spans="tyle--0:#5CA7E4;--1:#3A">688F{Let1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fu spans="tyle--0:#D6DEEB;--1:#40">3<}/u>

This rule is not configurable.

If you prefer the explicit negation syntax [^\d] for readability, or if your codebase has an established convention using negated character classes, you might prefer to disable this rule.