精读《正则 ES2018》

@ascoders 2019-02-11 14:09:50发表于 dt-fe/weekly

ES2018 推出了正则表达式的第九版规范,让 JS 正则功能更强大,也更易读了!

原文:New JavaScript Features That Will Change How You Write Regex

一起了解让人激动的新特性吧!

const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const [match, year, month, day] = re.exec('2020-03-04');

console.log(match);    // → 2020-03-04
console.log(year);     // → 2020
console.log(month);    // → 03
console.log(day);      // → 04

精读《正则 ES2018》