Glossary Term
RegExp.prototype[Symbol.replace]()
The Symbol.replace method of RegExp instances specifies how String.prototype.replace() and String.prototype.replaceAll() should behave when the regular expression is passed in as the pattern.
This method exists for customizing replace behavior in RegExp subclasses. It is called internally in String.prototype.replace() and String.prototype.replaceAll() if the pattern argument is a RegExp object. For example, the following two examples return the same result.
If the regex is global (with the g flag), its lastIndex is first set to 0, so matching always starts from the beginning of the string, and the regex’s exec() method is repeatedly called until exec() returns null. If the current match is an empty string, the lastIndex would still be advanced — if the regex is Unicode-aware, it would advance by one Unicode code point; otherwise, it advances by one UTF-16 code unit.
Syntax example: regexp[Symbol.replace](str, replacement)
Term Connections
Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.
Loading term connections…
