适用范围:
- 获取正则表达式匹配的完整信息
梗概:
字符串.matchAll(正则表达式)
- 无论匹配成功与否, 返回一个不可重复迭代的迭代器
- 如果没有匹配到东西, 则迭代器里面没有东西可以迭代
- 迭代器内容为RegExpMatchArray类型
- 每个元素都是RegExpMatch,表示一个匹配项
- child::判断迭代器内容是否为空
实例:
let str = "hello world"
let matches = str.matchAll(/l/g)
console.log(Array.from(matches))
/*
[
[ 'l', index: 2, input: 'hello world', groups: undefined ],
[ 'l', index: 3, input: 'hello world', groups: undefined ],
[ 'l', index: 9, input: 'hello world', groups: undefined ]
]
*/