JavaScript Regex Unicode Properties and Set Syntax
Quick answer
Unicode-aware regex modes allow code-point-aware matching and property escapes. The v mode additionally supports set operations and some string-valued Unicode properties.
How it works
Use \p{Decimal_Number} or \p{Script=Greek} with u or v; \P complements a property, subject to mode-specific case-folding rules. With v, intersections such as [\p{Letter}&&\p{Script=Greek}] are possible. u and v are mutually exclusive. Match indices still use UTF-16 offsets. Verify v support with a fixed constructor pattern in the intended runtime.
console.log(/\p{Decimal_Number}/u.test("۵"), /\d/u.test("۵"));Expected output in Node.js:
true falseThe Unicode decimal property includes the Persian digit; ASCII digit class does not.
const greekLetter = /[\p{Letter}&&\p{Script=Greek}]/v;console.log(greekLetter.test("α"), greekLetter.test("A"));Expected output in Node.js:
true falseThe v-mode intersection requires both properties.
Common mistakes
Unicode property matches do not validate natural-language words or security-sensitive identifiers by themselves.
Practice
Compare ASCII and Unicode digit matching with Persian digits; check target-runtime support before using v.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Regex Unicode Properties and Set Syntax — Knowledge Check
Apply the taught concept and predict the output.
Which flags enable Unicode-aware property escapes?
Which mode adds intersection syntax inside Unicode character classes?
Which unit is used for regex match indices even in Unicode-aware mode?
What is the exact console output in JavaScript Regex Unicode Properties and Set Syntax example 1?
console.log(/\p{Decimal_Number}/u.test("۵"), /\d/u.test("۵"));What is the exact console output in JavaScript Regex Unicode Properties and Set Syntax example 2?
const greekLetter = /[\p{Letter}&&\p{Script=Greek}]/v;console.log(greekLetter.test("α"), greekLetter.test("A"));