Standard built-ins
String.prototype.matchAll()
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
| Name | Type | Description |
|---|---|---|
| regexp | RegExp | String | Ordinary regex must have g. |
Return Value
Iterator
Iterator of match arrays.
Working Example
Example Snippetjavascript
console.log([..."a1 b2".matchAll(/\d/g)].length);