Description
The replace() method searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.
This method has the form:
string.replace(regexp/substr, newstring)
Parameter | Description |
---|---|
regexp/substr | (required) A substring or a regular expression |
newstring | (required) The string to replace the found value in parameter 1 |
Examples
The following example shows the basic use of this method.
<script>
var s = "Hello from JavaScript";
document.write(s.replace("JavaScript","Hawaii"));
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|