Below is an example of the String replaceAll() Method.
Geeks for Geeks
The replaceAll() method returns a new string after replacing all the matches of a string with a specified string or a regular expression.
The original string is left unchanged after this operation.
const newString = originalString.replaceAll(regexp | substr , newSubstr | function)
Parameters: This method accepts certain parameters defined below:
- regexp: It is the regular expression whose matches are replaced with the newSubstr or the value returned by the specified function.
- substr: It defines the sub strings which are to replace with newSubstr or the value returned by the specified function.
- newSubstr: It is the sub string that replaces all the matches of the string specified by the substr or the regular expression.
- function: It is the function that is invoked to replace the matches with the regexp or substr.
Hi, what are you doing?
Lets, have tea today!