---
page_title: replace function reference
description: |-
  The `replace` function replaces all occurrences of substring with a given string. 
---

# `replace` Function

`replace` searches a given string for another given substring, and replaces
each occurrence with a given replacement string.

```hcl
replace(string, substring, replacement)
```

## Examples

```shell-session
> replace("1 + 2 + 3", "+", "-")
1 - 2 - 3

> replace("hello world", "world", "everybody")
hello everybody
```

## Related Functions

- [`regex_replace`](/packer/docs/templates/hcl_templates/functions/string/regex_replace) searches a given string for another given substring,
  and replaces each occurrence with a given replacement string.
