mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
docs(regex): fixed matchall() #992
This commit is contained in:
parent
323e9620a7
commit
f0a92d5ff0
@ -690,8 +690,6 @@ matches
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const string = 'test1test2test3';
|
const string = 'test1test2test3';
|
||||||
|
|
||||||
// g 修饰符加不加都可以
|
|
||||||
const regex = /t(e)(st(\d?))/g;
|
const regex = /t(e)(st(\d?))/g;
|
||||||
|
|
||||||
for (const match of string.matchAll(regex)) {
|
for (const match of string.matchAll(regex)) {
|
||||||
@ -707,9 +705,10 @@ for (const match of string.matchAll(regex)) {
|
|||||||
遍历器转为数组是非常简单的,使用`...`运算符和`Array.from()`方法就可以了。
|
遍历器转为数组是非常简单的,使用`...`运算符和`Array.from()`方法就可以了。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// 转为数组方法一
|
// 转为数组的方法一
|
||||||
[...string.matchAll(regex)]
|
[...string.matchAll(regex)]
|
||||||
|
|
||||||
// 转为数组方法二
|
// 转为数组的方法二
|
||||||
Array.from(string.matchAll(regex))
|
Array.from(string.matchAll(regex))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user