---
title: "replace | Grafana Agent documentation"
description: "Learn about replace"
---

# replace

`replace` searches a string for a substring, and replaces each occurrence of the substring with a replacement string.

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

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

## Examples

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

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