JavaScript Replace
replace() returns a new string with the first match of the search value swapped out. Pass a plain string to replace one occurrence, or a regular expression with the /g flag to replace many.
Syntax
str.replace(search, replacement) Examples
| Input | Arguments | Output |
|---|---|---|
| "a-b-c" | "-", "+" | "a+b-c" |
| ↳ Only the first match is replaced. | ||
Gotchas
- A string search replaces only the first hit. Use replaceAll or a /g regex for all.
Try it live
Type your input and see Replace transform it instantly.
Want to go further? Chain Replace with other functions, pipe one output into the next and watch your data transform in the visual Playground.