Opens in a new tab
A picture of Jeff Brigman
I CODE TODAY FOR
A BETTER TOMORROW

Glossary Term

RegExp.prototype[Symbol.matchAll]()

2 tags 1 category

The Symbol.matchAll method of RegExp instances specifies how String.prototype.matchAll should behave.

This method exists for customizing the behavior of matchAll() in RegExp subclasses. It is called internally in String.prototype.matchAll(). For example, the following two examples return the same result.

Like [Symbol.split](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/Symbol.split), Symbol.matchAll starts by using [[Symbol.species]](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/Symbol.species) to construct a new regex, thus avoiding mutating the original regexp in any way. The constructor receives this and the original flags. lastIndex starts as the original regex’s value.

If the regex is global (with the g flag), each time the returned iterator’s next() method is called, the regex’s exec() is called and the result is yielded. If the current match is an empty string, the lastIndex will still be advanced. If the regex has the u flag, it advances by one Unicode code point; otherwise, it advances by one UTF-16 code point.

Syntax example: regexp[Symbol.matchAll](str)

Term Connections

Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.

Loading term connections…