Bookshelf Home | Contents | Index | Search | PDF | ![]() ![]() ![]() ![]() |
Siebel eScript Language Reference > Siebel eScript Commands > String Objects >
string.replace() Method
This method searches a string using the regular expression pattern defined by pattern. If a match is found, it is replaced by the substring defined by replexp.
Syntax
string.replace(pattern, replexp)
Parameter Description pattern Regular expression pattern to find or match in string. replexp Replacement expression which may be a string, a string with regular expression elements, or a function.Returns
The original string with replacements according to pattern and replexp.
Usage
The string is searched using the regular expression pattern defined by pattern. If a match is found, it is replaced by the substring defined by replexp. The parameter replexp may be:
- A simple string
- A string containing special regular expression replacement elements
- A function that returns a value that may be converted into a string
If any replacements are made, appropriate RegExp object static properties such as RegExp.leftContext, RegExp.rightContext, and RegExp.$n are set. These properties provide more information about the replacements.
The following table shows the special characters that may occur in a replacement expression.
Example
var rtn;
var str = "one two three two one";
var pat = /(two)/g;// rtn == "one zzz three zzz one"
rtn = str.replace(pat, "zzz");// rtn == "one twozzz three twozzz one";
rtn = str.replace(pat, "$1zzz");// rtn == "one 5 three 5 one"
rtn = str.replace(pat, five());// rtn == "one twotwo three twotwo one";
rtn = str.replace(pat, "$&$&);function five() {
return 5;}
See Also
Bookshelf Home | Contents | Index | Search | PDF | ![]() ![]() ![]() ![]() |
Siebel eScript Language Reference Published: 18 April 2003 |