replace (RegExp - JavaScript)
Replaces a substring.
Defined in
RegExp (Standard - JavaScript)Syntax
replace(searchString:string, replaceValue:string) : string
Parameters | Description |
---|---|
searchString |
The string to be searched. |
replaceValue |
The replacement substring. |
Return value | Description |
---|---|
string |
The string with the replacement made. |
Usage
ThisRegExp
object defines
the search criteria.If the string does not contain the substring to be replaced, the return value is the original string.
Examples
This example returns
Paris---Moscow---Tokyo
.var cities = new String("Paris Moscow Tokyo");
var regexp = new RegExp("( )", "g");
return regexp.replace(cities, "---")