On this page
String.replaceAll
Prev: includes | Up: String | Next: trim
Rel: String, String, RegExp & Intl Guide
Ref: MDN Web Docs — String.replaceAll
Tags: #public #web #javascript #builtins #string #tier/core
Signature & Overview
str.replaceAll(pattern, replacement)
Replaces all occurrences of a string or global RegExp (/g) without mutating str.
Notes & Pitfalls
- Replaces every occurrence cleanly: If passing a
RegExp, it MUST have the/gflag; replacement strings interpret$$/$&unless passed as a function() => literal.
Example
console.assert("a-b-c".replaceAll("-", "_") === "a_b_c");
Linked from
Related notes
- tuts/javascript/builtins/String/includes Linked here; links to this page; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/trim Linked here; links to this page; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String Linked here; links to this page; shared tags: #builtins, #javascript, #string, #web
- tuts/javascript/builtins/string_regexp_and_intl Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/String/matchAll shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/slice shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/split shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/substr shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/filter shared tags: #builtins, #javascript, #tier, #web