Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

RegExp.prototype.unicode

BaselineWidely available

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".
  • WhenlastIndex 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

js
const regex = /\u{61}/u;console.log(regex.unicode); // true

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-get-regexp.prototype.unicode

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp