Created
August 3, 2022 18:42
-
-
Save Minozzzi/926fab8dc356d5635f1ebe135867b1db to your computer and use it in GitHub Desktop.
Named Group Regex
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 = /(?<name>\w+)\s(?<age>\d+)/; | |
const matches = re.exec('John 30'); | |
const [match, name, age] = re.exec('John 30'); // ['John 30', 'John', '30'] | |
console.log(matches.groups); // { name: 'John', age: '30' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment