Explain how to use the replace () method in JavaScript, javascriptreplace
This method finds a match between strings of a regular expression and replaces a new substring of the matched substring.
The replacement string can contain the following special replacement modes:
Syntax
string.replace(regexp/substr, newSubStr/function[, flags]);
The following is the detailed information about the parameters:
- Regexp: A RegExp object. Response for matching the replaced parameter #2.
- Substr: a string that is replaced by newSubStr.
- NewSubStr: it replaces the substring received from the parameter #1.
- Function: a function is called to create a substring.
- Flags: Any combination string containing the regular expression flag: g-global match, I-case-insensitive, and m-matched multiple rows. This parameter is only used if the first parameter is a string.
Return Value:
Example:
The following example demonstrates how to use the global and case-insensitive flag, allow replacement, and replace 'append' with the string 'oranges'
Example:
The following example demonstrates how to convert words in a string: