Home >Web Front-end >JS Tutorial >About JS string function String.replace()_Basic knowledge
Replace the substring(s) matching the given regular expression
string.replace(regexp, replacement)
Parameters:
regexp: RegExp object or string
replacement: A string of replacement text, or a function used to generate the corresponding replacement text when called.
Return:
Returns a replaced new string
Description:
replacement can be a string or a function. If it is a function, it will be called on each match and the string it returns will be used as the replacement text.
Parameters passed into the function:
1) String matching the pattern
2) A string matching a certain parenthesis subexpression in the pattern, which may be 0 or more such parameters
3) Integer, specifying the position in String where the matching result appears
4) string itself
Example: