← TechnologyThe essentials of

replaceAll(): one substitution for all exact matches

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 10:06. This is not editorial approval.

In a few sentences

In brief

replaceAll() returns new text with all matches found replaced according to the specified rule.

Useful to know

To replace all occurrences of a specific text, replaceAll() can accept a text template and a replacement text. The method returns a new string and leaves the original unchanged. When regular expression is required the global flag g. [1]

The example '2026/10/21'.replaceAll('/', '-') gives '2026-10-21'. This is a conditional string conversion, not a date validation. '2026/99/99' would also go through the same replacement, although it is not a calendar date.

In a text search, symbols are seen as a literal sequence. This is often clearer than constructing a regular expression from a user input. You don't need to use regex for every simple replacement.

After the conversion, separately check the meaning of the result. Replacing a comma with a dot, for example, does not automatically decide how to read a number with separators for thousands or with a different local notation.

Sources

For further detail and to check the information:

  1. [1] MDN — String.replaceAll ↗