Understanding Unicode Categories
Every Unicode character is assigned a General Category—a two-letter classification code that describes the character's basic type and intended use. These categories are how text-processing algorithms, regular expressions, and rendering engines answer questions like "is this a letter?", "is this punctuation?", or "is this a space character?".
The Category Hierarchy
General categories are organised into major classes and subcategories. The letter L indicates a letter; Lu means uppercase letter, Ll means lowercase. Browse the full hierarchy in the categories browser.
- L – Letter: Lu (Uppercase), Ll (Lowercase), Lt (Titlecase), Lm (Modifier), Lo (Other)
- M – Mark: Mn (Non-spacing mark), Mc (Spacing combining mark), Me (Enclosing mark)
- N – Number: Nd (Decimal digit), Nl (Letter number), No (Other number)
- P – Punctuation: Ps (Open), Pe (Close), Pi (Initial quote), Pf (Final quote), Pd (Dash), Po (Other)
- S – Symbol: Sm (Math), Sc (Currency), Sk (Modifier), So (Other)
- Z – Separator: Zs (Space), Zl (Line), Zp (Paragraph)
- C – Other: Cc (Control), Cf (Format), Cs (Surrogate), Co (Private Use), Cn (Unassigned)
Categories in Regular Expressions
Most modern regex engines support Unicode category matching. In JavaScript (with the /u flag), \p{Lu} matches any Unicode uppercase letter and \p{Sc} matches any currency symbol—$, €, £, and many more. The PCRE and .NET regex engines have similar support.
This is far more robust than hardcoding character ranges. /^\p{L}+$/u matches any word made up of Unicode letters from any script, rather than just ASCII letters.
Why Categories Matter in Practice
Text segmentation algorithms use General Category to identify word boundaries, sentence boundaries, and grapheme clusters. A spell checker decides what constitutes a "word" partly by scanning for transitions between category classes. A number formatter uses Nd (decimal digit) to recognise digits in any script. The Arabic-Indic digit zero U+0660 is in category Nd, just like the ASCII 0 U+0030—relevant if your input validation only checks /^\d+$/ without the Unicode flag.