This method finds a match between the strings of a regular expression and replaces the new substring of the matched substring.
The replacement string can contain the following special substitution modes:
Grammar
String.Replace (REGEXP/SUBSTR, newsubstr/function[, flags]);
The following are the details of the parameters:
- RegExp: A RegExp object. Matches the return of the parameter being replaced.
- SUBSTR: A string that is replaced by newsubstr
- NEWSUBSTR: It replaces #1 of substrings received from parameters.
- Functions: A function is called to create a new substring
- Flags: Any combination string containing the regular expression flags: G-Global match, I-ignore case, M-matches multiple rows. This parameter is only used if the first parameter is a string.
return value:
- It just returns a new change to the string
Example:
The following example shows how to use global and ignore case flags to allow substitution to use the string ' oranges ' instead of ' apples '
Example:
The following example shows how to convert a word in a string: