RegExp.prototype.unicode
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
Theunicode
accessor property ofRegExp
instances returns whether or not theu
flag is used with this regular expression.
Try it
const regex1 = /\u{61}/;const regex2 = /\u{61}/u;console.log(regex1.unicode);// Expected output: falseconsole.log(regex2.unicode);// Expected output: true
Description
RegExp.prototype.unicode
has the valuetrue
if theu
flag was used; otherwise,false
. Theu
flag enables various Unicode-related features. With the "u" flag:
- AnyUnicode code point escapes (
\u{xxxx}
,\p{UnicodePropertyValue}
) will be interpreted as such instead of identity escapes. For example/\u{61}/u
matches"a"
, but/\u{61}/
(withoutu
flag) matches"u".repeat(61)
, where the\u
is equivalent to a singleu
. - Surrogate pairs will be interpreted as whole characters instead of two separate characters. For example,
/[😄]/u
would only match"😄"
but not"\ud83d"
. - When
lastIndex
is automatically advanced (such as when callingexec()
), unicode regexes advance by Unicode code points instead of UTF-16 code units.
There are other changes to the parsing behavior that prevent possible syntax mistakes (which are analogous tostrict mode for regex syntax). These syntaxes are alldeprecated and only kept for web compatibility, and you should not rely on them.
The set accessor ofunicode
isundefined
. You cannot change this property directly.
Unicode-aware mode
When we refer toUnicode-aware mode, we mean the regex has either theu
or thev
flag, in which case the regex enables Unicode-related features (such asUnicode character class escape) and has much stricter syntax rules. Becauseu
andv
interpret the same regex in incompatible ways, using both flags results in aSyntaxError
.
Similarly, a regex isUnicode-unaware if it has neither theu
nor thev
flag. In this case, the regex is interpreted as a sequence of UTF-16 code units, and there are many legacy syntaxes that do not become syntax errors.
Examples
Using the unicode property
const regex = /\u{61}/u;console.log(regex.unicode); // true
Specifications
Specification |
---|
ECMAScript® 2026 Language Specification # sec-get-regexp.prototype.unicode |