JavaScript replace() Method
Complete RegExp Object Reference
Definition and Usage
The replace() method is used to replace some characters in a string with some
other characters.
This method supports regular expressions.
Syntax
stringObject.replace(regexp,str)
|
Parameter |
Description |
regexp |
Required. The regular expression to find and replace |
newstring |
Required. Specifies the replacement string |
Tips and Notes
Note: The replace() method is case sensitive.
Example
In the following example we will replace "the" with "Ze":
<script type="text/javascript">
var str = "The Lord of the Rings: The Fellowship of the Ring";
var result = str.replace(/The/gi, "Ze");
document.write(result);
</script>
|
Try-It-Yourself Demos
replace()
How to use replace() to replace some characters in a string using a regular expression.
Complete RegExp Object Reference
|
|
|
See why there are 20,000+ Ektron integrations worldwide.
Request an INSTANT DEMO or download a FREE TRIAL today. |
|
|
|