`
subclasses.

##  Examples

###  Direct call

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

js

    
    
    const re = /-/g;
    const str = "2016-01-02";
    const result = re[Symbol.search](str);
    console.log(result); // 4
    

###  Using @@search in subclasses

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

js

    
    
    class MyRegExp extends RegExp {
      constructor(str) {
        super(str);
        this.pattern = str;
      }
      [Symbol.search](str) {
        return str.indexOf(this.pattern);
      }
    }
    
    const re = new MyRegExp("a+b");
    const str = "ab a+b";
    const result = str.search(re); // String.prototype.search calls re[@@search].
    console.log(result); // 3
    

##  Specifications

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

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

##  See also

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

##  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  Apr 28, 2023  by  [ MDN contributors ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@search/contributors.txt)
.

[ View this page on GitHub
](https://github.com/mdn/content/blob/main/files/en-
us/web/javascript/reference/global_objects/regexp/@@search/index.md?plain=1
"Folder: en-us/web/javascript/reference/global_objects/regexp/@@search \(Opens
in a new tab\)") â¢  [ Report a problem with this content
](https://github.com/mdn/content/issues/new?template=page-report.yml&mdn-
url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FRegExp%2F%40%40search&metadata=%3C%21--+Do+not+make+changes+below+this+line+--%3E%0A%3Cdetails%3E%0A%3Csummary%3EPage+report+details%3C%2Fsummary%3E%0A%0A*+Folder%3A+%60en-
us%2Fweb%2Fjavascript%2Freference%2Fglobal_objects%2Fregexp%2F%40%40search%60%0A*+MDN+URL%3A+https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FRegExp%2F%40%40search%0A*+GitHub+URL%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fblob%2Fmain%2Ffiles%2Fen-
us%2Fweb%2Fjavascript%2Freference%2Fglobal_objects%2Fregexp%2F%40%40search%2Findex.md%0A*+Last+commit%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fcommit%2F6bd17cb9cbc2d11163617b9f71706e93fdd743c8%0A*+Document+last+modified%3A+2023-04-28T03%3A58%3A12.000Z%0A%0A%3C%2Fdetails%3E
"This will take you to GitHub to file a new issue.")

[ MDN log