regexUnicodeEscapes
Enforces consistent Unicode escape style in regex patterns by preferring codepoint escapes.
✅ This rule is included in the ts stylistic presets.
Enforces consistent Unicode escape style in regex patterns by preferring \u{XXXX} (codepoint escape) over \uXXXX (4-digit Unicode escape) when the u or v flag is present.
The \u{...} format is more flexible, readable, and consistent with the modern Unicode handling in JavaScript.
Examples
Section titled “Examples”Basic Unicode Escape
Section titled “Basic Unicode Escape”const pattern = /\u0041/u;const pattern = /\u{0041}/u;Character Class
Section titled “Character Class”const pattern = /[\u0041\u0042]/u;const pattern = /[\u{0041}\u{0042}]/u;Character Range
Section titled “Character Range”const pattern = /[\u0041-\u005A]/u;const pattern = /[\u{0041}-\u{005A}]/u;With v Flag
Section titled “With v Flag”const pattern = /\u0041/v;const pattern = /\u{0041}/v;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you need to support environments that do not have the u or v flag, or if you intentionally use 4-digit Unicode escapes as a stylistic preference, you might want to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/unicode-escape
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.