正则表达式 patterns

基本用法见 MDN

Captures

const pattern = /(\d{4})-(\d{2})-(\d{2})/
pattern.exec('2017-07-10')

Named captures

(?<name>)

const pattern = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
pattern.exec('2017-07-10')

Named backreferences

const pattern = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
pattern.exec('2017-07-10')

String.prototype.replace

const pattern = /(?<first>a)(?<second>b)/
'ab'.replace(pattern, '$<second>$<first>') // 'ba'
'ab'.replace(pattern, (m, p1, p2, o, s, {first, second}) => fst + snd)) // 'ba'

chromestatus

Lookarounds assertions

lookahead assertions

https://github.com/tc39/proposal-regexp-lookbehind

资料