Match by Unicode property, not by listing characters
\p{...} matches any character with the given Unicode property. The complement is \P{...}. This unlocks portable Unicode-aware patterns without listing every character.
Common properties
\p{L}— any letter (any script)\p{Ll}— lowercase letter\p{Lu}— uppercase letter\p{N}— any number-like (digits, fractions, Roman numerals, etc.)\p{Nd}— decimal digit (any script's digits)\p{P}— punctuation\p{S}— symbol (math, currency, modifier)\p{Z}— separator (space, line)\p{Mn}— non-spacing mark (combining diacritics)
Script properties
\p{Script=Hangul} matches Korean Hangul syllables. \p{Script=Han} matches CJK ideographs. \p{Script=Latin} for Latin script. Useful for filtering by writing system.
Engine support
- Python
regexthird-party: Full support. - Python
re: No\p{...}, but\d,\w,\sare Unicode-aware by default. - JavaScript: Yes, with
/uflag. - PCRE, Java, .NET, Ruby: Yes.
- Go RE2: Yes (uses RE2 syntax).
When to use
Anytime you're processing multilingual text. [\p{L}\p{N}_] is a portable Unicode-aware identifier pattern, working for Korean variable names, Cyrillic, Arabic, anything. [a-zA-Z0-9_] only works for ASCII.