You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!

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

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
@@searchChrome Full support YesEdge Full support YesFirefox Full support 49IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 49Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support 6.0.0


Full support  
Full support
No support  
No support

See also