Skip to content

regexOctalEscapes

Reports octal escape sequences in regular expressions.

✅ This rule is included in the ts logical and logicalStrict presets.

Reports octal escape sequences in regular expressions. Octal escapes like \7 or \07 can be confused with backreferences. The same sequence (e.g., \2) may be a character or a backreference depending on the number of capturing groups in the pattern.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#F78C6C;--1:#AA09">82<\0sp 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:#F78C6C;--1:#AA">0982<\x07 spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<07/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F<\7sp 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:#F78C6C;--1:#AA">0982<\x07 spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<07/>
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F\1<\2sp 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:#F78C6C;--1:#AA">0982\x01<\x02 spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<02/>

In the incorrect example, \1 and \2 are octal escapes (matching characters with code 1 and 2). If capturing groups are added later, they could become backreferences.

This rule is not configurable.

If you intentionally use octal escapes for specific character matching and understand the distinction from backreferences, you might want to disable this rule. Octal escapes inside character class ranges (e.g., [\1-\4]) are allowed.