Unicode Propiedad Escapes en Regex
Unicode General Categoría y Binary propiedad escapes para matching script y carácter clases.
General Categories
Unicode property escapes of the form backslash-p{Category} match characters belonging to a Unicode general category or binary property. These require the Unicode flag u on the regular expression. General categories include Letter, Number, Punctuation, and Symbol, with subcategories like Uppercase_Letter and Decimal_Number. Property escapes enable matching by semantic class rather than code point ranges, which is more robust across Unicode versions.
- \p{L}
- Any letter, any script
- \p{N}
- Any number, any script
- \p{P}
- Any punctuation
- \p{Sc}
- Currency symbol
- \p{Script=Han}
- Characters of the Han script
matches A, 中, ا matches 1, ٢, Ⅷ matches ., ,, 。 matches $, €, ¥ matches Chinese chars Binary Properties
Binary properties are boolean attributes that a character either has or lacks. Common binary properties include White_Space, Alphabetic, Emoji, and Emoji_Presentation. The Emoji property is useful for matching emoji code points, though combining sequences require additional handling. Negated property escapes use capital P and match characters lacking the property. Binary properties are stable across Unicode versions more than general categories.
Script Segmentation
The Script property identifies the writing system of a character, such as Latin, Cyrillic, or Han. The Script_Extensions property handles characters used in multiple scripts, such as digits shared between scripts. Matching by script is useful for validating input in a specific language or segmenting mixed-script text. The Unicode flag is mandatory for property escapes, and omitting it causes a syntax error rather than a silent ASCII-only match.