Skip to content

Instantly share code, notes, and snippets.

@parkerziegler
Created April 25, 2021 01:39
Show Gist options
  • Save parkerziegler/df00be164fb29795dc0d7dda986b4fe6 to your computer and use it in GitHub Desktop.
Save parkerziegler/df00be164fb29795dc0d7dda986b4fe6 to your computer and use it in GitHub Desktop.
An example of how to name capture groups in regular expressions for easier access.
const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const match = re.exec('2021-04-24');
const { year, month, day } = match.groups;
console.log({ year, month, day });
// { year: '2021', month: '04', day: '24' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment