Standard built-ins

String.prototype.matchAll()

Try the free JavaScript compiler

Returns an iterator over match records; ordinary global regex matching uses a cloned regex state.

Formal Syntax & Structure

javascript syntaxjavascript
text.matchAll(regexp)

Parameters & Attributes

NameTypeDescription
regexpRegExp | StringOrdinary regex must have g.

Return Value

Iterator

Iterator of match arrays.

Working Example

Example Snippetjavascript
console.log([..."a1 b2".matchAll(/\d/g)].length);
JavaScript Reference