We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

Наши волонтёры ещё не перевели данную статью на Русский. Присоединяйтесь к нам и помогите сделать эту работу!
Вы можете также прочитать эту статью на English (US).

The [@@match]() method retrieves the matches when matching a string against a regular expression.




A String that is a target of the match.

Return value

An Array containing the entire match result and any parentheses-captured matched results, or null if there were no matches.


This method is called internally in String.prototype.match(). For example, the following two examples return same result.



This method exists for customizing match behavior within RegExp subclasses.


Direct call

This method can be used in almost the same way as String.prototype.match(), except the different this and the different arguments order.

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

Using @@match in subclasses

Subclasses of RegExp can override the [@@match]() method to modify the default behavior.

class MyRegExp extends RegExp {
  [Symbol.match](str) {
    var result = RegExp.prototype[Symbol.match].call(this, str);
    if (!result) return null;
    return {
      group(n) {
        return result[n];

var re = new MyRegExp('([0-9]+)-([0-9]+)-([0-9]+)');
var str = '2016-01-02';
var 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


Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'RegExp.prototype[@@match]' in that specification.
Standard Initial defintion.
ECMAScript Latest Draft (ECMA-262)
The definition of 'RegExp.prototype[@@match]' in that specification.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes Yes49 No Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes49 Yes Yes ?

See also

Метки документа и участники

 Внесли вклад в эту страницу: wbamberg, schalkneethling, fscholz, Sebastianz, h4writer, arai
 Обновлялась последний раз: wbamberg,