Skip to content

Instantly share code, notes, and snippets.

@shisama shisama/string_matchAll.js
Last active Nov 28, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.