String.prototype.matchAll() - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

regular expression

The matchAll() method of String values returns an iterator of all results matching this string against a regular expression, including capturing groups.

iterable iterator object

An iterable iterator object (which is not restartable) of matches or an empty iterator if no matches are found. Each value yielded by the iterator is an array with the same shape as the return value of RegExp.prototype.e

RegExp.prototype.exec()

An iterable iterator object (which is not restartable) of matches or an empty iterator if no matches are found. Each value yielded by the iterator is an array with the same shape as the return value of RegExp.prototype.e

RegExp.prototype[Symbol.matchAll]()

The implementation of String.prototype.matchAll doesn't do much other than calling the Symbol.matchAll method of the argument with the string as the first parameter (apart from the extra input validation that the regex i

Regexp.prototype.exec() and matchAll()

Without matchAll(), it's possible to use calls to regexp.exec() (and regexes with the g flag) in a loop to obtain all the matches:

Regexp.prototype.exec() and matchAll()

Without matchAll(), it's possible to use calls to regexp.exec() (and regexes with the g flag) in a loop to obtain all the matches:

Regexp.prototype.exec() and matchAll()

Without matchAll(), it's possible to use calls to regexp.exec() (and regexes with the g flag) in a loop to obtain all the matches:

Regexp.prototype.exec() and matchAll()

Without matchAll(), it's possible to use calls to regexp.exec() (and regexes with the g flag) in a loop to obtain all the matches:

Better access to capturing groups (than String.prototype.match())

Another compelling reason for matchAll is the improved access to capture groups.

Groups and backreferences

RegExp.prototype.test()

Learn how to contribute

This page was last modified on Jul 10, 2025 by MDN contributors.

toLocaleLowerCase()

toLocaleUpperCase()

[Symbol.iterator]()

[Symbol.hasInstance]()