matchAll
MatchAll is a JavaScript string method that returns an iterator over all matches of a regular expression against a string. Introduced with ECMAScript 2020, it enables retrieving every occurrence, including capture groups, rather than stopping at the first match. The regular expression passed to matchAll must have the global flag (/g).
Each item yielded by the iterator is a RegExp match array. The full matched text is at
Because matchAll returns an iterator, you typically consume it with a for...of loop or by converting it
Usage notes: ensure the environment supports ECMAScript 2020 features, as older runtimes may not implement matchAll.
Example concept: for a string like "cat1 dog2" and a global regex /(\w+)(\d)/g, matchAll yields two matches