Javascript replace() String Method

Last Updated Jul 29, 2015, 07:00:14 PM

The javascript string replace() method will find the matched string and replace that old string with new string in its place


Argument Details

regexp A RegExp object. The match is replaced by the return value of parameter #2.

substr A String that is to be replaced by newSubStr.

newSubStr The String that replaces the substring received from parameter #1.

function A function to be invoked to create the new substring.

flags A String containing any combination of the RegExp flags: g - global match, i - ignore case, m - match over multiple lines. This parameter is only used if the first parameter is a string.


The flags argument does not work in v8 Core (Chrome and Node.js).


Try It Now

Sources and Credits

The source of the content has been referred and updated with Mozilla Developer Network and W3C Organization

Last Updated Jul 29, 2015, 07:00:14 PM

Browser compatibility

replace() Yes Yes Yes Yes Yes Yes Yes