Skip to content

Instantly share code, notes, and snippets.

@Minozzzi
Created August 3, 2022 18:42
Show Gist options
  • Save Minozzzi/926fab8dc356d5635f1ebe135867b1db to your computer and use it in GitHub Desktop.
Save Minozzzi/926fab8dc356d5635f1ebe135867b1db to your computer and use it in GitHub Desktop.
Named Group Regex
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