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.

const pattern = /\u000a/;
const pattern = /\u{a}/u;
const pattern = /\u{00ff}/u;

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.

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