RegExp.prototype.unicodeSets
RegExp 实例的 unicodeSets 访问器属性返回此正则表达式是否使用 v 标志。
¥The unicodeSets accessor property of RegExp instances returns whether or not the v flag is used with this regular expression.
描述
¥Description
如果使用了 v 标志,则 RegExp.prototype.unicodeSets 的值为 true;否则,false。v 标志是 "upgrade" 到 u 标志,可启用更多与 Unicode 相关的功能。("v" 是字母表中 "u" 之后的下一个字母。)由于 u 和 v 以不兼容的方式解释相同的正则表达式,因此使用这两个标志会产生 SyntaxError。使用 v 标志,你可以获得 u 标志描述中提到的所有功能,以及:
¥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:
\p转义序列还可用于匹配字符串的属性,而不仅仅是字符。- 字符类 语法已升级为允许交集、并集和减法语法,以及匹配多个 Unicode 字符。
- 字符类补码语法
[^...]构造一个补码类,而不是否定匹配结果,避免了不区分大小写匹配的一些令人困惑的行为。欲了解更多信息,请参阅 补充类和不区分大小写的匹配。
一些有效的 u 模式正则表达式在 v 模式下变得无效。具体来说,字符类语法不同,某些字符不能再按字面形式出现。欲了解更多信息,请参阅 v-模式字符类。
¥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.
注意:
v模式不会将字素簇解释为单个字符;它们仍然是多个代码点。例如,/[🇺🇳]/v仍然能够匹配"🇺"。¥Note: The
vmode does not interpret grapheme clusters as single characters; they are still multiple code points. For example,/[🇺🇳]/vis still able to match"🇺".
unicodeSets 的集合访问器是 undefined。你不能直接更改此属性。
¥The set accessor of unicodeSets is undefined. You cannot change this property directly.
示例
使用 unicodeSets 属性
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-get-regexp.prototype.unicodesets |
浏览器兼容性
BCD tables only load in the browser