Skip to content

Instantly share code, notes, and snippets.

@shisama
Last active November 28, 2019 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shisama/eebdaedfcff471177877c1ca7a5ff5c0 to your computer and use it in GitHub Desktop.
Save shisama/eebdaedfcff471177877c1ca7a5ff5c0 to your computer and use it in GitHub Desktop.
let regexp = /t(e)(st(\d?))/g;
let str = 'test1test2';
str.match(regexp);
// Array ['test1', 'test2']
let array = [...str.matchAll(regexp)];
console.log(array[0]);
// Array ["test1", "e", "st1", "1"]
console.log(array[1]);
// Array ["test2", "e", "st2", "2"]
for (const arr of str.matchAll(regexp)) {
console.log(arr)
}
// Array ["test1", "e", "st1", "1"]
// Array ["test2", "e", "st2", "2"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment