Skip to content

regexHexadecimalEscapes

Reports regex character escapes that can be expressed more consistently using hexadecimal escapes.

✅ This rule is included in the ts stylisticStrict presets.

Characters in the range 0x00-0xFF can be expressed using either hexadecimal escapes (\xNN) or Unicode escapes (\uNNNN, \u{N}). Hexadecimal escapes are more concise for this range and provide a consistent representation. This rule enforces the use of hexadecimal escapes for characters that can be represented in two hex digits.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#F78C6C;--1:#AA09">82\u00<0asp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#F78C6C;--1:#AA09">82<\usp ansty="le--0:#5CA7E4;--1:#3A68">8F{1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#F78C6C;--1:#AA09">82<\usp ansty="le--0:#5CA7E4;--1:#3A68">8F{00f1<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">0982<\x0a spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<0a/><;di vdivclass="Nameexpressive-">44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#F78C6C;--1:#AA">0982<\xff spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fu spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">6376// Unicode escapes are fine for values > <0xF Fdivclass="Nameec-">44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#F78C6C;--1:#AA">0982\u<0100 spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fu spans="tyle--0:#D6DEEB;--1:#40">3<0/u><;di vdivclass="Nameexpressive-">6376// Control characters with standard escapes are 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0\t<\n\r spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<\r/>

This rule is not configurable.

If your codebase has established conventions around using Unicode escapes for consistency with characters outside the 0x00-0xFF range, you might prefer to disable this rule. Some teams prefer the uniformity of always using Unicode escapes regardless of the character value.