The [@@search]() method executes a search for a match between a this regular expression and a string.




A String that is a target of the search.

Return value

If successful, [@@search]() returns the index of the first match of the regular expression inside the string. Otherwise, it returns -1.


This method is called internally in For example, the following two examples return the same result.



This method exists for customizing the search behavior in RegExp subclasses.


Direct call

This method can be used in almost the same way as, except the different this and the different arguments order.

var re = /-/g;
var str = '2016-01-02';
var result = re[](str);
console.log(result);  // 4

Using @@search in subclasses

Subclass of RegExp can override [@@search]() method to modify the behavior.

class MyRegExp extends RegExp {
  constructor(str) {
    this.pattern = str;
  [](str) {
    return str.indexOf(this.pattern);

var re = new MyRegExp('a+b');
var str = 'ab a+b';
var result =; // calls re[@@search].
console.log(result); // 3


Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'RegExp.prototype[@@search]' in that specification.
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
The definition of 'RegExp.prototype[@@search]' 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 Yes

See also

Document Tags and Contributors

Contributors to this page: wbamberg, schalkneethling, fscholz, h4writer, rolfedh, arai
Last updated by: wbamberg,