Skip to content

regexUnicodeEscapes

Enforces consistent Unicode escape style in regex patterns by preferring codepoint escapes.

✅ This rule is included in the ts preset.

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.

const
const pattern: RegExp
pattern
= /\u0041/u;
const
const pattern: RegExp
pattern
= /[\u0041\u0042]/u;
const
const pattern: RegExp
pattern
= /[\u0041-\u005A]/u;
const
const pattern: RegExp
pattern
= /\u0041/v;
Error ts(1501) ― This regular expression flag is only available when targeting 'es2024' or later.

This rule is not configurable.

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. This rule is not enabled by default in Flint because the preference for \u{...} over \uXXXX is more opinionated than what most projects prefer.

Made with ❤️‍🔥 around the world by the Flint team and contributors.