Last Updated : 05 Aug, 2025
The unicode property of a JavaScript regular expression object indicates whether the u (Unicode) flag is enabled. When this flag is set, the regular expression operates in full Unicode mode, allowing correct handling of Unicode characters, such as surrogate pairs, Unicode code points, and properties.
JavaScript
// Regular expression without 'u' flag
let regex1 = /\u{1F600}/;
console.log(regex1.unicode);
// Regular expression with 'u' flag
let regex2 = /\u{1F600}/u;
console.log(regex2.unicode);
regex.unicodeKey Points
// Emoji 😀 (code point U+1F600)
let regex = /\u{1F600}/u;
console.log(regex.test("😀"));
console.log(regex.test("smile"));
The u flag ensures the pattern correctly matches the full Unicode code point.
2. Using Unicode Property Escapes JavaScript
let regex = /\p{Script=Greek}/u;
console.log(regex.test("α"));
console.log(regex.test("a"));
The u flag enables matching based on Unicode properties like script, block, or general categories.
3. Handling Surrogate Pairs JavaScript
let s = "😀";
// Emoji stored as a surrogate pair in UTF-16
let regex = /[\uD83D\uDE00]/;
// Matches the individual UTF-16 units
let regexUnicode = /\u{1F600}/u;
// Matches the full code point
console.log(regex.test(s));
console.log(regexUnicode.test(s));
Without the u flag, matching surrogate pairs requires specifying both UTF-16 units.
4. Differentiating Characters and Code Points JavaScript
let regex = /^.$/;
let regexUnicode = /^.$/u;
console.log(regex.test("😀"));
console.log(regexUnicode.test("😀"));
The u flag ensures that . matches a full Unicode character, not just a single UTF-16 code unit.
5. Combining Property Escapes with Other Patterns JavaScript
let regex = /\p{L}\d+/u;
// Match letters followed by digits
console.log(regex.test("A123"));
console.log(regex.test("1A23"));
The u flag makes advanced Unicode patterns like property escapes possible.
Why Use the unicode Property?The unicode property is essential for working with modern text containing diverse Unicode characters, ensuring accuracy and consistency in JavaScript regular expressions.
Recommended Links:RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4