The replace() method is used to replace some characters with other characters in a string, or replace a substring that matches a regular expression.
It should be noted that: If regexp has the global flag g when replacing with a regular expression, then the replace() method will replace all matching substrings. Otherwise, it only replaces the first matching substring.
The following is a simple example: