replace()  String  instance method getterS2C Home
      « Globals « String « replace()
Description
Returns a new string containing some or all of the matches of a replaced pattern.
- The pattern to replace can be a string or a regular expresion.
- For each match the pattern can be replaced by another string or the result of a called function.
Syntax
| Signature | Description | 
|---|---|
| aString.replace(regexp|substr, replacementSubstr|function) | Returns a new string containing some or all of the matches of a replaced pattern. | 
Parameters
| Parameter | Description | 
|---|---|
| regexp | A regular expression or RegExpobject orsubstr. | 
| substr | A part of the string to be replaced. | 
| replacementSubstr | the string to replace substr or one of the following patterns: 
 | 
| function | an invoked Functionwith the following arguments:
 | 
Examples
The code below replaces part of a string.
// Create a string variable.
  var aNewSentence = 'I like to shine my nose';
/*
 Replace part of the string.
 /*
alert(aNewSentence.replace('nose', 'shoes'));
Related Tutorials
JavaScript Basic Tutorials - Lesson 8 - Strings
 
  
  
  
 Homepage
 Homepage Top
 Top