Skip to content

regexUnicodeCodepointEscapes

Reports surrogate pair escapes in regular expressions that can be replaced with Unicode codepoint escapes.

✅ This rule is included in the ts stylistic presets.

Reports surrogate pair escapes in regular expressions that can be replaced with Unicode codepoint escapes. When the u or v flag is present, surrogate pairs like \uD83D\uDE00 can be written as \u{1F600}. Unicode codepoint escapes are clearer and more maintainable.

const emoji = /\uD83D\uDE00/u;
const emoji = /[\uD83D\uDE00]/u;
const emoji = /\uD83D\uDE00/v;
const emoji = new RegExp("\\uD83D\\uDE00", "u");

This rule is not configurable.

If you need to support environments that do not support Unicode codepoint escapes, or if you prefer surrogate pairs for consistency with existing code, you might need to disable this rule. Without the u or v flag, surrogate pairs are required for astral characters.

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