大网数据广告活动
Web 标准与前端开发

RegExp.prototype.unicodeSets

· 52CE 我爱测

The **`unicodeSets`** accessor property of RegExp instances returns whether or not the `v` flag is used with this regular expression.

The unicodeSets accessor property of RegExp instances returns whether or not the v flag is used with this regular expression.

JavaScript Demo: RegExp.prototype.unicodeSets

const regex1 = /[α-ω]/u;
const regex2 = /[\p{Lowercase}&&\p{Script=Greek}]/v;

console.log(regex1.unicodeSets);
// Expected output: false

console.log(regex2.unicodeSets);
// Expected output: true

Description

RegExp.prototype.unicodeSets has the value true if the v flag was used; otherwise, false. The v flag is an "upgrade" to the u flag that enables more Unicode-related features. ("v" is the next letter after "u" in the alphabet.) Because u and v interpret the same regex in incompatible ways, using both flags results in a SyntaxError. With the v flag, you get all features mentioned in the u flag description, plus:

  • The \p escape sequence can be additionally used to match properties of strings, instead of just characters.
  • The character class syntax is upgraded to allow intersection, union, and subtraction syntaxes, as well as matching multiple Unicode characters.
  • The character class complement syntax [^...] constructs a complement class instead of negating the match result, avoiding some confusing behaviors with case-insensitive matching. For more information, see Complement classes and case-insensitive matching.

Some valid u-mode regexes become invalid in v-mode. Specifically, the character class syntax is different and some characters can no longer appear literally. For more information, see v-mode character class.

[!NOTE] The v mode does not interpret grapheme clusters as single characters; they are still multiple code points. For example, /[🇺🇳]/v is still able to match "🇺".

The set accessor of unicodeSets is undefined. You cannot change this property directly.

Examples

Using the unicodeSets property

const regex = /[\p{Script_Extensions=Greek}&&\p{Letter}]/v;

console.log(regex.unicodeSets); // true

Specifications

Browser compatibility

See also

  • RegExp.prototype.lastIndex
  • RegExp.prototype.dotAll
  • RegExp.prototype.global
  • RegExp.prototype.hasIndices
  • RegExp.prototype.ignoreCase
  • RegExp.prototype.multiline
  • RegExp.prototype.source
  • RegExp.prototype.sticky
  • RegExp.prototype.unicode
  • RegExp v flag with set notation and properties of strings on v8.dev (2022)

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。