would not be reset. In this case, each call to ` match() ` may
return a different result.

js

    
    
    const re = /[abc]/y;
    for (let i = 0; i < 5; i++) {
      console.log("abc".match(re), re.lastIndex);
    }
    // [ 'a' ] 1
    // [ 'b' ] 2
    // [ 'c' ] 3
    // null 0
    // [ 'a' ] 1
    

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

js

    
    
    console.log("ab-c".match(/[abc]/gy)); // [ 'a', 'b' ]
    

If the current match is an empty string, the ` lastIndex ` would still be
advanced â if the regex is [ Unicode-aware ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode#unicode-
aware_mode) , it would advance by one Unicode code point; otherwise, it
advances by one UTF-16 code unit.

js

    
    
    console.log("ð".match(/(?:)/g)); // [ '', '', '' ]
    console.log("ð".match(/(?:)/gu)); // [ '', '' ]
    

This method exists for customizing match behavior within ` RegExp `
subclasses.

In addition, the ` @@match ` property is used to check [ whether an object is
a regular expression ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#special_handling_for_regexes)
.

##  Examples

###  Direct call

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

js

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

###  Using @@match in subclasses

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

js

    
    
    class MyRegExp extends RegExp {
      [Symbol.match](str) {
        const result = RegExp.prototype[Symbol.match].call(this, str);
        if (!result) return null;
        return {
          group(n) {
            return result[n];
          },
        };
      }
    }
    
    const re = new MyRegExp("([0-9]+)-([0-9]+)-([0-9]+)");
    const str = "2016-01-02";
    const result = str.match(re); // String.prototype.match calls re[@@match].
    console.log(result.group(1)); // 2016
    console.log(result.group(2)); // 01
    console.log(result.group(3)); // 02
    

##  Specifications

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

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

##  See also

  * [ Polyfill of ` RegExp.prototype[@@match] ` in ` core-js ` ](https://github.com/zloirock/core-js#ecmascript-string-and-regexp)
  * [ ` String.prototype.match() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
  * [ ` RegExp.prototype[@@matchAll]() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@matchAll)
  * [ ` 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)
  * [ ` RegExp.prototype.exec() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
  * [ ` RegExp.prototype.test() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
  * [ ` Symbol.match ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)

##  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 la