Web/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[@@replace]()

The **` [@@replace]() ` ** method of [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instances specifies
how [ ` String.prototype.replace() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) and [ `
String.prototype.replaceAll() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) should
behave when the regular expression is passed in as the pattern.

##  Try it

##  Syntax

js

    
    
    regexp[Symbol.replace](str, replacement)
    

###  Parameters

` str `

    

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

` replacement `

    

Can be a string or a function.

  * If it's a string, it will replace the substring matched by the current regexp. A number of special replacement patterns are supported; see the [ Specifying a string as the replacement ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement) section of ` String.prototype.replace ` . 
  * If it's a function, it will be invoked for every match and the return value is used as the replacement text. The arguments supplied to this function are described in the [ Specifying a function as the replacement ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_the_replacement) section of ` String.prototype.replace ` . 

###  Return value

A new string, with one, some, or all matches of the pattern replaced by the
specified replacement.

##  Description

This method is called internally in [ ` String.prototype.replace() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) and [ `
String.prototype.replaceAll() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) if the `
pattern ` argument is a [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) object. For example,
the following two examples return the same result.

js

    
    
    "abc".replace(/a/, "A");
    
    /a/[Symbol.replace]("abc", "A");
    

If the regex is global (with the ` g ` flag), the regex's [ ` exec() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method will be
repeatedly called until ` exec() ` returns ` null ` . Otherwise, ` exec() `
would only be called