Function Updated 17 Oct 2026
String.replaceAll(pattern, replacement)
Returns a new string where every occurrence of the search text is replaced. The original string is not changed.
With a regular expression, the flags decide: without the g flag only the first match is replaced (standard JavaScript throws an error instead).
Parameters
patternstring | RegExprequiredText or regular expression to search for. Text is matched exactly (case-sensitive).
replacementstring | functionrequiredReplacement text, or a function called for each match whose return value is inserted.
Returns
A new string. Searching for empty text returns the string unchanged.
Example
Normal JavaScript, running in the browser or on the Docly™ server.
write("2026-10-17".replaceAll("-", ".")); // 2026.10.17
write("\n");
write("a+b+c".replaceAll("+", " plus ")); // a plus b plus cThe JavaScript above produces this output:
2026.10.17
a plus b plus c