Replaces the matched pattern with the replacement string.
The target string.
The pattern to match.
The replacement string or a function that returns the replacement string.
The new string with the matched pattern replaced.
replace('abcde', 'de', '123'); // 'abc123'replace('abcde', /[bd]/g, '-'); // 'a-c-e'replace('abcde', 'de', substring => substring.toUpperCase()); // 'abcDE'replace('abcde', /[bd]/g, substring => substring.toUpperCase()); // 'aBcDe' Copy
replace('abcde', 'de', '123'); // 'abc123'replace('abcde', /[bd]/g, '-'); // 'a-c-e'replace('abcde', 'de', substring => substring.toUpperCase()); // 'abcDE'replace('abcde', /[bd]/g, substring => substring.toUpperCase()); // 'aBcDe'
Alias