SOURCE

//ES2018允许命名捕获组使用符号?<name>,在打开捕获括号(后立即命名,示例如下:

const
  reDate = /(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})/,
  match  = reDate.exec('2018-04-30'),
  year   = match.groups.year,  // 2018
  month  = match.groups.month, // 04
  day    = match.groups.day;   // 30
    console.log(match);
    console.log(year);
    console.log(month);
    console.log(day);
//任何匹配失败的命名组都将返回undefined。

//命名捕获也可以使用在replace()方法中。例如将日期转换为美国的 MM-DD-YYYY 格式:

  d      = '2018-04-30',
  usDate = d.replace(reDate, '$<month>-$<day>-$<year>');

   console.log(usDate);


console.log('-----------------------------------------');
//原有的 match() 方法仅返回完整的匹配结果,却不会返回特定正则表达式组。
//而 matchAll()返回的迭代器不仅包括精确的匹配结果,还有全部的正则模式捕获结果
var str = 'From 2019.01.29 to 2019.01.30';
var allMatchs = str.matchAll(/(?<year>\d{4}).(?<month>\d{2}).(?<day>\d{2})/g);

for (const match1 of allMatchs) {
  console.log(match1);
}
console 命令行工具 X clear

                    
>
console