JavaScript RegExp unicode Property

Beginner
5 min read
Updated: Nov 2026
3 examples
RegExp

Definition

In JavaScript, regex.unicode is a read-only boolean. It is true when the RegExp was created with the u flag.

With u, the engine treats the pattern as Unicode code points. That matters for emoji and other characters outside the basic multilingual plane, and it enables escapes like \u{1F600}.

Syntax

Create the regex with u, then read .unicode.

JavaScript
const a = /./;
const b = /./u;
const c = new RegExp(".", "u");

console.log(a.unicode); // false
console.log(b.unicode); // true
console.log(c.unicode); // true
CallWhat it does
/./uUnicode mode. unicode is true.
/\u{1F600}/uMatch an emoji by code point escape.
new RegExp(".", "u")Same as the literal with u.

Remember this at a glance:

Remember
 /./.unicode       → false
 /./u.unicode      → true

with u:
  . matches one code point (not half a surrogate pair)
  \u{1F600} emoji escapes work

flags are fixed at creation

What You Get

NameDescription
regex.unicodeRead-only. true if the u flag was set when the RegExp was created.
u flagSet at creation with /…/u or new RegExp(pattern, "u").
Code pointsWith u, patterns and . work on full Unicode characters.

Return Value

ValueDescription
trueThe RegExp has the u (unicode) flag.
falseThe RegExp does not have the u flag.

JavaScript Examples

Example 1 — Read unicode

See how the u flag sets the property.

JavaScript
const a = /a/;
const b = /a/u;
const c = new RegExp("a", "u");

console.log(a.unicode);
console.log(b.unicode);
console.log(c.unicode);
console.log(c.flags);
Try It Yourself

How It Works

  1. Without u, unicode is false.
  2. With /a/u, unicode is true.
  3. The constructor with "u" does the same.
  4. flags reports "u".

Example 2 — Match one emoji as one character

Compare . with and without u on an emoji.

JavaScript
const smile = "😀";

console.log(smile.length);
console.log(/./.exec(smile)[0].length);
console.log(/./u.exec(smile)[0]);
console.log(/./u.exec(smile)[0].length);
Try It Yourself

How It Works

  1. In JavaScript strings, many emoji have length 2 (two code units).
  2. Without u, . can match only one code unit.
  3. With u, . matches the whole emoji as one code point.

Example 3 — Use a code point escape

With u, \u{…} escapes are allowed.

JavaScript
const re = /\u{1F600}/u;

console.log(re.test("😀"));
console.log(re.unicode);
console.log(re.source);
Try It Yourself

How It Works

  1. \u{1F600} is the grinning face emoji.
  2. The pattern matches only when u is set.
  3. source shows the pattern text without the flags.

Frequently Asked Questions

It is true when the regex was created with the u flag. The engine then treats patterns as Unicode code points.
Many emoji are stored as two UTF-16 code units. Without u, . and some classes can split them. With u, they are one character.
A Unicode code point escape. It works in regex patterns when the u flag is set.
No. unicode (u) enables Unicode mode. unicodeSets (v) adds set notation and is a newer flag.
No. Create a new RegExp with the u flag.
With u, some Unicode-aware behaviors apply. For simple ASCII word characters the difference is small; for full Unicode text, prefer u.

Next: unicodeSets

Use the v flag for Unicode sets and character class improvements.

unicodeSets tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful