mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-20 02:09:26 -05:00
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com> Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Signed-off-by: Roman Grinovski <roman.grinovski@gmail.com> Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
38 lines
1.0 KiB
Plaintext
38 lines
1.0 KiB
Plaintext
---
|
|
sidebar_label: replace
|
|
description: |-
|
|
The replace function searches a given string for another given substring,
|
|
and replaces all occurrences with a given replacement 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)
|
|
```
|
|
|
|
If `substring` is wrapped in forward slashes, it is treated as a regular
|
|
expression, using the same pattern syntax as
|
|
[`regex`](../../language/functions/regex.mdx). If using a regular expression for the substring
|
|
argument, the `replacement` string can incorporate captured strings from
|
|
the input by using an `$n` sequence, where `n` is the index or name of a
|
|
capture group.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> replace("1 + 2 + 3", "+", "-")
|
|
1 - 2 - 3
|
|
|
|
> replace("hello world", "/w.*d/", "everybody")
|
|
hello everybody
|
|
```
|
|
|
|
## Related Functions
|
|
|
|
- [`regex`](../../language/functions/regex.mdx) searches a given string for a substring matching a
|
|
given regular expression pattern.
|