Stringobj is required. String object or text to be replaced. This object will not be modified by the replace method.
Rgexp is required. A regular expression object that describes the content to be searched.
Replacetext is required. Is a String object or text. For each position in stringobj that matches rgexp, it is replaced by the text contained in this object.
The following example demonstrates the replace method usage:
Function replacedemo ()
{
VaR R, RE;
VaR S = "The quick brown fox jumped over the lazy yellow dog .";
Re =/Fox/I;
R = S. Replace (Re, "pig ");
Return (R );
}
In addition, the replace method can replace the subexpression in the mode. The following example demonstrates each pair of words in the exchange string:
Function replacedemo ()
{
VaR R, RE;
VaR S = "The quick brown fox jumped over the lazy yellow dog .";
Re =/(\ s +)/g;
R = S. Replace (Re, "$3 $2 $1"); // exchange each pair of words.
Return (R );
}
If the Replace () method in Javascript uses Str. Replace ("-","! ") Only the first matched character. Str. Replace (/\-/g ,"! "), You can replace all matched characters (G is the global flag ).