ed.

When the regex is sticky and global, it will still perform sticky matches â
i.e. it will not match any occurrences beyond the ` lastIndex ` .

js

    
    
    console.log(Array.from("ab-c".matchAll(/[abc]/gy)));
    // [ [ "a" ], [ "b" ] ]
    

If the current match is an empty string, the [ ` lastIndex ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) will still
be advanced. If the regex has the [ ` u ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode) flag, it
advances by one Unicode code point; otherwise, it advances by one UTF-16 code
point.

js

    
    
    console.log(Array.from("ð".matchAll(/(?:)/g)));
    // [ [ "" ], [ "" ], [ "" ] ]
    
    console.log(Array.from("ð".matchAll(/(?:)/gu)));
    // [ [ "" ], [ "" ] ]
    

This method exists for customizing the behavior of ` matchAll() ` in [ `
RegExp ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
subclasses.

##  Examples

###  Direct call

This method can be used in almost the same way as [ `
String.prototype.matchAll() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll) , except for
the different value of ` this ` and the different order of arguments.

js

    
    
    const re = /[0-9]+/g;
    const str = "2016-01-02";
    const result = re[Symbol.matchAll](str);
    
    console.log(Array.from(result, (x) => x[0]));
    // [ "2016", "01", "02" ]
    

###  Using @@matchAll in subclasses

Subclasses of [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) can override the `
[@@matchAll]() ` method to modify the default behavior.

For example, to return an [ ` Array ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Array) instead of an [
iterator ](/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators) :

js

    
    
    class MyRegExp extends RegExp {
      [Symbol.matchAll](str) {
        const result = RegExp.prototype[Symbol.matchAll].call(this, str);
        return result ? Array.from(result) : null;
      }
    }
    
    const re = new MyRegExp("([0-9]+)-([0-9]+)-([0-9]+)", "g");
    const str = "2016-01-02|2019-03-07";
    const result = str.matchAll(re);
    
    console.log(result[0]);
    // [ "2016-01-02", "2016", "01", "02" ]
    
    console.log(result[1]);
    // [ "2019-03-07", "2019", "03", "07" ]
    

##  Specifications

Specification  
---  
[ ECMAScript Language Specification  
#  sec-regexp-prototype-matchall  ](https://tc39.es/ecma262/multipage/text-
processing.html#sec-regexp-prototype-matchall)  
  
##  Browser compatibility

BCD tables only load in the browser  with JavaScript enabled. Enable
JavaScript to view data.

##  See also

  * [ Polyfill of ` RegExp.prototype[@@matchAll] ` in ` core-js ` ](https://github.com/zloirock/core-js#ecmascript-string-and-regexp)
  * [ ` String.prototype.matchAll() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
  * [ ` RegExp.prototype[@@match]() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@match)
  * [ ` RegExp.prototype[@@replace]() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@replace)
  * [ ` RegExp.prototype[@@search]() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@search)
  * [ ` RegExp.prototype[@@split]() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@split)
  * [ ` Symbol.matchAll ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/matchAll)

##  Help improve MDN

Was this page helpful to you?

Yes  No

[ Learn how to contribute
](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you
to our contribution guidelines on GitHub.") .

This page was last modified on  Sep 12, 2023  by  [ MDN contributors ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@matchAll/contributors.txt)
.

[ View this page on GitHub
](https://github.com/mdn/content/blob/main/files/en-
us/web/javascript/reference/global_objects/regexp/@@matchall/i