Created
April 25, 2021 01:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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