Skip to content

Commit cc18cea

Browse files
committed
docs(regex): edit v flag
1 parent f6e88af commit cc18cea

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/regex.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ regexArrows.test('←↑→↓↔↕↖↗↘↙⇏⇐⇑⇒⇓⇔⇕⇖⇗⇘
483483

484484
## v 修饰符:Unicode 属性类的运算
485485

486-
有时,需要向某个 Unicode 属性类添加或减少字符,即需要对属性类进行运算。现在有一个[提案](https://github.com/tc39/proposal-regexp-v-flag)增加了 Unicode 属性类的运算功能。
486+
有时,需要向某个 Unicode 属性类添加或减少字符,即需要对属性类进行运算。[ES2024](https://github.com/tc39/proposal-regexp-v-flag) 增加了 Unicode 属性类的运算功能。
487487

488488
它提供两种形式的运算,一种是差集运算(A 集合减去 B 集合),另一种是交集运算。
489489

@@ -516,6 +516,22 @@ regexArrows.test('←↑→↓↔↕↖↗↘↙⇏⇐⇑⇒⇓⇔⇕⇖⇗⇘
516516
[\p{Emoji}--\p{ASCII}]
517517
```
518518

519+
看一个实际的例子,`0`属于十进制字符类。
520+
521+
```javascript
522+
/[\p{Decimal_Number}]/u.test('0') // true
523+
```
524+
525+
上面示例中,字符类是 Unicode 专用的,所以必须使用`u`修饰符。
526+
527+
如果把`0-9`从十进制字符类里面去掉,那么`0`就不属于这个类了。
528+
529+
```javascript
530+
/[\p{Decimal_Number}--[0-9]]/v.test('0') // false
531+
```
532+
533+
上面示例中,`v`修饰符只能用于 Unicode,所以可以省略`u`修饰符。
534+
519535
## 具名组匹配
520536

521537
### 简介

0 commit comments

Comments
 (0)