Docly Developers
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 | RegExprequired

Text or regular expression to search for. Text is matched exactly (case-sensitive).

replacementstring | functionrequired

Replacement 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 c