RegExp.prototype[Symbol.matchAll]
Returns an iterator of all results matching a string against a regular expression, including capturing groups
Syntax
regexp[Symbol.matchAll](str)Parameters
| Parameter | Type | Description |
|---|---|---|
| str | string | The string to match against |
Return Value
An iterable iterator of matches
Examples
const regex = /\d+/g;
const str = 'a1 b22 c333';
const matches = [...str.matchAll(regex)];
matches.forEach(m => console.log(m[0]));
// '1', '22', '333'const regex = /(\w+)=(\w+)/g;
const str = 'a=1&b=2&c=3';
for (const match of str.matchAll(regex)) {
console.log(match[1], '=', match[2]);
}const regex = /(?<word>\w+)/g;
const matches = [...'hello world'.matchAll(regex)];
matches.forEach(m => console.log(m.groups?.word));Understanding RegExp.prototype[Symbol.matchAll]
The RegExp.prototype[Symbol.matchAll] method in JavaScript returns an iterator of all results matching a string against a regular expression, including capturing groups. It belongs to the RegExp object and is one of the most widely used methods for working with regexp values in modern JavaScript and TypeScript applications.
The method signature is regexp[Symbol.matchAll](str). It accepts 1 parameter: str. When called, it returns an iterable iterator of matches. Understanding when and how to use matchAll() helps you write more expressive, readable code.
Common use cases for RegExp.prototype[Symbol.matchAll] include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like regexp-exec, regexp-test, string-matchall, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for RegExp.prototype[Symbol.matchAll] is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
RegExp.prototype.execExecutes a search for a match in a specified string and returns a result array or null
RegExp.prototype.testExecutes a search for a match between a regular expression and a specified string, returning true or false
String.prototype.matchAllReturns an iterator of all results matching a string against a regular expression, including capturing groups
More RegExp Methods
Other methods in the RegExp object
Related Tools
More RegExp Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.