RegExp-named captured groups(命名分組捕獲)

console.log('2020-01-23'.match(/(\d{4})-(\d{2})-(\d{2})/))

const t = '2020-01-23'.match(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/)
console.log(t.groups.year)
console.log(t.groups.month)
console.log(t.groups.day)
相關文章
相關標籤/搜索