Unicode property escapes let a regular expression match meaning rather than a narrow list of code points. This cross-language reference explains how to match letters, numbers, scripts, emoji, punctuation, and whitespace in JavaScript, Python, PHP, Java, and other common runtimes, while showing where syntax and Unicode-version support differ.
Overview
A pattern such as [A-Za-z] only describes a small part of the world's writing systems. It excludes accented Latin letters, Greek, Cyrillic, Arabic, Han characters, and many other letters. Unicode-aware regular expressions provide broader categories through properties such as Letter, Number, Script=Greek, and White_Space.
The most recognizable syntax is \p{Property=Value}, with the uppercase form \P{...} meaning “not this property.” General categories also have short forms: \p{L} matches letters, \p{N} matches numbers, \p{M} matches combining marks, \p{P} matches punctuation, and \p{S} matches symbols. The exact property names, flags, and supported categories depend on the regex engine.
Property matching is not the same as grapheme-cluster matching. A visible character may contain a base letter plus combining marks, and an emoji may be a sequence joined by zero-width joiners. For those cases, test complete user-perceived characters rather than assuming one regex match equals one displayed symbol. The related guides on using Unicode safely in web formats and emoji sequences provide useful background.
How to compare options
Before copying a Unicode regex, compare five details:
- Property syntax: Does the engine accept
\p{L}, long names such as\p{Letter}, or script syntax such as\p{Script=Greek}? - Flags and modes: JavaScript needs the Unicode-aware
uflag for property escapes. Other engines may require a Unicode or character-class mode, or may interpret Unicode properties by default. - Script behavior: A script property describes writing-system membership. A general category describes character type. They answer different questions: “Is this Greek?” is not the same as “Is this a letter?”
- Unicode data version: Runtime libraries and regex engines can recognize different sets of recently assigned characters. Pin and test the runtime used in production.
- String-level matching: Determine whether the engine handles only individual code points or also supports properties of strings, grapheme clusters, and emoji sequences.
Use a representative test corpus rather than a handful of English examples. Include accented text, combining marks, scripts used by your users, non-ASCII digits, punctuation, emoji sequences, and malformed input. The Unicode test corpus guide can help organize those fixtures.
| Runtime or engine | Typical property form | Important consideration |
|---|---|---|
| JavaScript | /\p{Letter}+/u | Property escapes require Unicode mode; support varies by runtime and browser version. |
Python re | Use explicit ranges or another regex library | The standard module does not provide Perl-style \p{...} escapes; a third-party Unicode-aware engine may be appropriate. |
| PHP PCRE2 | /\p{L}+/u | The u modifier enables UTF-8 interpretation; confirm the PCRE2 build and Unicode data. |
| Java | \p{L}+ or \p{IsGreek}+ | Java string literals require doubled backslashes, such as "\\p{L}+". |
| .NET | \p{L}+ or \p{IsGreek}+ | Use the engine's Unicode category and script naming conventions; validate behavior on the target framework. |
| Go RE2 | \p{L}+ | Unicode categories are available, but advanced PCRE features such as lookaround are not generally interchangeable. |
Feature-by-feature breakdown
Letters, numbers, marks, and separators
For a multilingual name or search field, start with a category-based pattern:
\p{L}[\p{L}\p{M}\p{N}\p{Pc}\p{Pd}]*
This describes a letter followed by letters, combining marks, numbers, connector punctuation, or dash punctuation. It is only a starting point: real names may contain apostrophes, spaces, format characters, or script-specific conventions. Avoid treating it as a universal legal-name validator.
To match decimal digits, use \p{Nd} rather than \d when the distinction matters. To match whitespace, consider \p{White_Space} where supported. A shorthand such as \s may include a runtime-defined set that is useful for parsing but not identical to every Unicode whitespace property.
Scripts
Script matching is useful for routing, search filters, and diagnostics:
\p{Script=Greek}+
\p{Script=Cyrillic}+
\p{Script=Han}+
Some engines use an abbreviated form such as \p{sc=Greek}, or a named form such as \p{IsGreek}. In JavaScript, Script_Extensions can be more suitable than Script for characters that are commonly used with more than one script. Prefer the long, documented spelling when portability and reviewability matter.
Emoji and symbols
A property such as \p{Extended_Pictographic} can identify many pictographic code points, but it does not by itself match every complete emoji displayed by a user. Skin-tone modifiers, variation selectors, regional indicators, and zero-width-joiner sequences complicate matching. For emoji-aware interfaces, separate validation from rendering and test actual sequences. Do not use a single broad symbol pattern as an assumption that all symbols are emoji.
Negation and security boundaries
\P{L} means “not a letter,” but it also matches punctuation, controls, symbols, and possibly unexpected input. For allowlists, an explicit positive category is usually easier to reason about than a broad negated class. Normalize and validate at a clearly defined boundary, then apply length limits and safe output encoding. Regex properties do not replace HTML escaping, SQL parameterization, or authorization checks.
Best fit by scenario
- Multilingual search: Use Unicode letter and mark properties, then handle case folding, normalization, and locale-sensitive comparison separately. Intl.Collator guidance is relevant for JavaScript sorting and filtering.
- Script detection: Use script properties as a heuristic, not as proof of a language. A language can use several scripts, and a script can serve several languages.
- Identifiers: Follow the identifier rules of the language or protocol instead of inventing a generic “letters and numbers” regex. Combining marks, confusables, and normalization can affect safety and equality.
- Whitespace cleanup: Match the intended whitespace property and decide whether line breaks, non-breaking spaces, and zero-width characters should be preserved.
- Python projects: If
\p{...}is required, select a maintained Unicode-capable regex implementation and document that dependency. Otherwise, use Python's Unicode-aware string methods for simpler operations. - Browser validation: Test the oldest supported browser and server-side validator. Client and server regex engines may accept different properties or Unicode versions.
When to revisit
Recheck a Unicode regex when you upgrade a browser, language runtime, standard library, PCRE package, or regex dependency. Unicode data can change as new characters are assigned, and an engine may add property support or alter compatibility details. Treat those changes as test inputs rather than assuming a pattern's behavior is permanently fixed.
Revisit the pattern when your product adds a language, accepts names from a new region, introduces emoji reactions, or moves validation from one runtime to another. Keep a small cross-runtime test suite with expected matches and non-matches. Record the runtime versions, regex flags, normalization policy, and intended user-facing behavior beside the pattern.
As a practical workflow, first define the text rule in plain language; then choose the narrowest Unicode property that expresses it; verify syntax in the target engine; test composed and decomposed text; and finally test the same fixtures in every production runtime. For code-point details, the Unicode character lookup guide is useful. For broader compatibility concerns, see the guide to Unicode versions in browsers, JavaScript, ICU, and regex.