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.

const pattern = /\07/;
const pattern = /\7/;
const pattern = /\1\2/;

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.