This article mainly introduces the use of JavaScript in the Replace () method, is the basic knowledge of JS learning, need friends can refer to the
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
?
| 1 |
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 '
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16 |
|
Example:
The following example shows how to convert a word in a string:
?