Skip to content

Instantly share code, notes, and snippets.

@kutyel
Created July 5, 2018 07:47
Show Gist options
  • Save kutyel/3e01f249ce54a8bfd6b44ae5fbea8a05 to your computer and use it in GitHub Desktop.
Save kutyel/3e01f249ce54a8bfd6b44ae5fbea8a05 to your computer and use it in GitHub Desktop.
const regex = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u
const result = regex.exec('2018-07-05')
console.log(result[0]) // > '2018-07-05'
console.log(result[1]) // > '2018'
console.log(result[2]) // > '07'
console.log(result[3]) // > '05'
console.log(result.groups.year) // > '2018'
console.log(result.groups.month) // > '07'
console.log(result.groups.day) // > '05'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment