Level 3: Advanced · Lesson 24 of 30
Unicode and Non-Latin Text
\w and [a-z] only cover basic Latin letters in JavaScript. With the u flag, Unicode properties such as \p{L} and \p{Script=Arabic} match letters from any language.
Many regex tutorials quietly assume English text. In JavaScript, \w means [A-Za-z0-9_] and \d means [0-9]. That is fine for code and identifiers, but it fails as soon as your data contains a name like café, a Greek city such as Αθήνα, or a word in Arabic script. \w+ would split café into caf and drop the accented letter completely.
The solution is Unicode property escapes. With the u flag, \p{L} matches any letter in any script, \p{Lu} matches uppercase letters, \p{N} matches any number, and \p{Nd} matches decimal digits, including Arabic-Indic digits like ٣٤٥. The opposite, \P{L}, matches anything that is not a letter.
You can also target a writing system with \p{Script=...}. The pattern \p{Script=Arabic}+ matches runs of Arabic-script letters, \p{Script=Greek}+ matches Greek words, and \p{Script=Cyrillic}+ matches Cyrillic. This is useful when a document mixes languages and you want to extract only one of them.
The u flag is required. Without it, JavaScript treats \p as a plain p and your pattern silently matches the wrong thing. The flag also makes the engine treat characters outside the Basic Multilingual Plane, such as many emoji, as single characters rather than two halves of a surrogate pair, so . and character classes behave correctly.
Support differs across languages. Java, C#, Go, Rust and Ruby support \p{L} directly. PHP needs its own u modifier. Python's built-in re module does not support \p{L} at all; you either use a class like [^\W\d_] or install the third-party regex module. Note also that Python, C# and Rust treat \w and \d as Unicode-aware by default, while JavaScript, Go, Java, PHP and Ruby default to ASCII.
Right-to-left scripts need no special regex syntax. Text is stored in logical order, so a pattern reads characters in the order they were typed, even though they display from right to left.
When your input comes from real people, reach for \p{L} instead of [A-Za-z] for names and words. It is the difference between a form that works worldwide and one that rejects many of its users.
Live tester
2 matches (JavaScript engine)
Greeting: مرحبا and thanks: شكرا
Examples
Numbers
/\p{Nd}+/uTotals ٣٤٥ and 678
Matches: “٣٤٥”, “678”
`\p{Nd}` matches Arabic-Indic digits as well as ASCII digits, unlike JavaScript's `\d`.
Text
/\p{L}+/ucafé, naïve and Ελλάδα
Matches: “café”, “naïve”, “and”, “Ελλάδα”
Accented Latin and Greek words are matched whole instead of being split at accented letters.
Codes
/\p{Lu}{2}\d{3}/uCodes ÅB123 and ÉZ456
Matches: “ÅB123”, “ÉZ456”
`\p{Lu}` accepts uppercase letters with accents that `[A-Z]` would reject.
Practice tasks
Your regex runs over the text with the global flag. It passes when it finds every required match and nothing that should be left out.
Task 1: Match whole words, including accented letters, so that `café` is not cut short.
café and naïve plans
Task 2: Match only the words written in Arabic script.
Order مرحبا 12 شكرا done
Task 3: Match only the Greek words.
alpha Αθήνα beta Ελλάδα