JavaScript Replace all

replaceAll() returns a new string with every occurrence of the search value replaced. It is the natural fix for replace()’s "first match only" behaviour, without needing a global regex.

Syntax

str.replaceAll(search, replacement)

Examples

Input Arguments Output
"a-b-c" "-", "+" "a+b+c"

Gotchas

  • With a regex argument the /g flag is mandatory, or it throws.

Try it live

Type your input and see Replace all transform it instantly.

Replace all()

Type above to see the result…

Want to go further? Chain Replace all with other functions, pipe one output into the next and watch your data transform in the visual Playground.

Related functions

© 2026 Heifara Buval