Skip to content

Instantly share code, notes, and snippets.

@ondrej-kvasnovsky
Created July 7, 2020 20:14
Show Gist options
  • Save ondrej-kvasnovsky/752bcaf2423c57221790a0cd3b9793d2 to your computer and use it in GitHub Desktop.
Save ondrej-kvasnovsky/752bcaf2423c57221790a0cd3b9793d2 to your computer and use it in GitHub Desktop.
JavaScript get Regex groups
const input = 'hi:ha:ho';
const matches = input.match(/(.*):(.*):(.*)/);
const firstGroup = matches[1];
const secondGroup = matches[2];
const thirdGroup = matches[3];
console.log(firstGroup, secondGroup, thirdGroup);
// prints out: hi ha ho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment