ECMAScript question detail
String matchAll
There is String#match method to get all the matches of a string against a regular expression by iterating for each match. However this method gives you the substrings that match.
The String#matchAll() is a new method added to String prototype, which returns an iterator of all results matching a string against a regular expression.
const regex = /t(e)(st(\d?))/g;
const string = 'test1test2';
const matchesIterator = string.matchAll(regex);
Array.from(matchesIterator, result => console.log(result));
When you this code in browser console, the matches iterator produces an array for each match including the capturing groups with a few extras.
["test1", "e", "st1", "1", index: 0, input: "test1test2", groups: undefined]
["test2", "e", "st2", "2", index: 5, input: "test1test2", groups: undefined]