正则表达式-regex-正则

适用范围:

  1. 获取正则表达式匹配的完整信息

梗概:

字符串.matchAll(正则表达式)

  1. 无论匹配成功与否, 返回一个不可重复迭代迭代器
    1. 如果没有匹配到东西, 则迭代器里面没有东西可以迭代
    2. 迭代器内容为RegExpMatchArray类型
      1. 每个元素都是RegExpMatch,表示一个匹配项
    3. 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 ]
]
*/