JavaScript/Reference/Global_Objects/Object/constructor)
    2. [ ` Object.prototype.__proto__ ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) Deprecated 
  13. Methods 
    1. [ ` Object.prototype.__defineGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) Deprecated 
    2. [ ` Object.prototype.__defineSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__) Deprecated 
    3. [ ` Object.prototype.__lookupGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__) Deprecated 
    4. [ ` Object.prototype.__lookupSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__) Deprecated 
    5. [ ` Object.prototype.hasOwnProperty() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
    6. [ ` Object.prototype.isPrototypeOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
    7. [ ` Object.prototype.propertyIsEnumerable() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
    8. [ ` Object.prototype.toLocaleString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
    9. [ ` Object.prototype.toString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
    10. [ ` Object.prototype.valueOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)

##  In this article

  * Try it 
  * Syntax 
  * Description 
  * Examples 
  * Specifications 
  * Browser compatibility 
  * See also 

#  RegExp.prototype[@@search]()

The **` [@@search]() ` ** method of [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instances specifies
how [ ` String.prototype.search ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/search) should behave.

##  Try it

##  Syntax

js

    
    
    regexp[Symbol.search](str)
    

###  Parameters

` str `

    

A [ ` String ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
that is a target of the search.

###  Return value

The index of the first match between the regular expression and the given
string, or ` -1 ` if no match was found.

##  Description

This method is called internally in [ ` String.prototype.search() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/search) . For example,
the following two examples return the same result.

js

    
    
    "abc".search(/a/);
    
    /a/[Symbol.search]("abc");
    

This method does not copy the regular expression, unlike [ ` @@split ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@split) or [ `
@@matchAll ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@matchAll) . However,
unlike [ ` @@match ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@match) or [ `
@@replace ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@replace) , it will
set [ ` lastIndex ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) to 0 when
execution starts and restore it to the previous value when it exits, therefore
generally avoiding side effects. This means that the ` g ` flag has no effect
with this method, and it always returns the first match in the string even
when ` lastIndex ` is non-zero. This also means sticky regexps will always
search strictly at the beginning of the string.

js

    
    
    const re = /[abc]/g;
    re.lastIndex = 2;
    console.log("abc".search(re)); // 0
    
    const re2 = /[bc]/y;
    re2.lastIndex = 1;
    console.log("abc".search(re2)); // -1
    console.log("abc".match(re2)); // [ 'b' ]
    

` @@search ` always calls the regex's [ ` exec() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method exactly
once, and returns the ` index ` property of the result, or ` -1 ` if the
result is ` null ` .

This method exists for customizing the search behavior in ` RegExp