Skip to main content
🔍 JavaScript / PCRE / Cross-Language Standard: Unicode Technical Standard #18 / ECMA-262 Time: 8 min read Reviewed: September 2024

Unicode in Regex: Property Escapes & Flags

Match international alphabets, scripts, and emojis accurately using \p{L}, \p{Script}, \p{Extended_Pictographic}, and modern RegExp flags.

TL;DR — Direct Answer

Direct Technical Answer

Standard regex character classes (\w, \d, [a-z]) match only ASCII characters and fail on international text. Modern regex engines support Unicode mode (the /u or /v flag in ECMAScript) and Unicode Property Escapes (\p{...}) to match characters based on their official Unicode properties.

💡
Production Rule: Use \p{L} to match any international letter in any alphabet; use \p{Extended_Pictographic} to match emojis; always enable the /u or /v flag when matching Unicode text.

Essential Unicode Property Escapes

The most commonly required Unicode property escapes supported across modern engines.

\p{L} or \p{Letter}

Matches: Any letter in any language (Latin, Greek, Cyrillic, Arabic, Hebrew, CJK, etc.)

Example: a, é, Ω, Ж, ش, א, 漢

\p{N} or \p{Number}

Matches: Any numeric character or digit (including Roman numerals, subscript/superscript)

Example: 5, ², Ⅳ, ٥

\p{P} or \p{Punctuation}

Matches: Any punctuation character

Example: !, ?, —, «, », ¿

\p{Z} or \p{Separator}

Matches: Any whitespace or invisible separator

Example: Space, non-breaking space, em-space

\p{Extended_Pictographic}

Matches: All emoji and pictographic symbols

Example: 😀, 🔥, 🚀, 🎉

\p{Script=Greek}

Matches: Characters specific to the Greek script

Example: α, β, γ, Δ

Matching international letters and emojis with Unicode property escapes

JAVASCRIPT unicode-regex.js
// 1. Traditional \w fails on accented letters and non-Latin alphabets
const asciiRegex = /^\w+$/;
console.log(asciiRegex.test('José'));     // false!
console.log(asciiRegex.test('Müller'));   // false!

// 2. Unicode property escape \p{L} matches any letter in Unicode
const unicodeNameRegex = /^[\p{L}]+$/u;
console.log(unicodeNameRegex.test('José'));     // true!
console.log(unicodeNameRegex.test('Müller'));   // true!
console.log(unicodeNameRegex.test('Владимир')); // true (Cyrillic)!
console.log(unicodeNameRegex.test('田中'));     // true (Kanji)!

// 3. Matching Emojis with \p{Extended_Pictographic}
const emojiRegex = /\p{Extended_Pictographic}/u;
console.log(emojiRegex.test('Hello 🔥!'));     // true!
Program Output
false
false
true
true
true
true
true

Common Mistakes vs Production Patterns

Learn which patterns fail in production and the modern standards-compliant alternatives.

Matching Emojis Safely

Chat validation, input sanitization, reaction filters.
AVOID: ❌ Brittle Character Ranges
const badEmojiRegex = /[\u1F600-\u1F64F]/; // Matches only one block!
Why it fails: Emojis span dozens of disparate Unicode blocks. Hardcoded ranges miss food, animals, flags, and new symbols introduced in recent Unicode releases.
RECOMMENDED: ✅ \p{Extended_Pictographic}
const goodEmojiRegex = /\p{Extended_Pictographic}/u;
goodEmojiRegex.test('🔥'); // true
goodEmojiRegex.test('🍣'); // true
Why it's better: Formally standardized by Unicode UTS #51 to match all present and future pictographic symbols.

Edge Cases & Invariants Matrix

A diverse cross-character test matrix comparing character behavior across ASCII, combining marks, emojis, flags, and surrogate fragments.

Test Case Input Glyph Code Units Code Points Graphemes Category Technical Explanation
Accented Name Renée Standard Both base letters and accented letters match \p{L}.
Cyrillic Text Привет Standard Cyrillic letters match \p{L} under Unicode mode.
CJK Ideographs 東京 Standard Matches Kanji/Han characters explicitly.

Standards & Source Provenance

All technical invariants, APIs, and behaviors in this guide are verified against official primary specifications.

Unicode Consortium

Unicode Technical Standard #18: Unicode Regular Expressions

Clause: §1.2 Properties

Ecma International

ECMAScript 2024 Language Specification

Clause: §22.2 RegExp (Regular Expression) Objects