JavaScript Replace | JS Replace | JavaScript String Replace Tutorial By WDH

JavaScript Replace


JavaScript replace
replace()
This method finds a match between a regular expression and a string, and replaces matched substring with a new substring.
This replacement substring can include the following special replacement patterns:
Syntax
String.replace(repExp/substr,newSubstr/function[,flags]);
Example
Output
 
Parameters  
 
Parameter
 
Description
 
regexp
 
A RegExp object. The match is replaced by the return value of parameter #2.
 
substr
 
A string that is to be replaced by a new substr.
 
newSubStr
 
The string that replaces the substring received from parameter #1
 
Function 
 
A function to be created is invoked to create the new substring. 
 
Flags
 
A string containing any combination of the RegExp flags: g – global match over multiple lines. This parameter is only used if the first parameter is a string.
 
Return Value
It simply returns a new changed string.