github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/replace.mdx (about) 1 --- 2 page_title: replace - Functions - Configuration Language 3 description: |- 4 The replace function searches a given string for another given substring, 5 and replaces all occurrences with a given replacement string. 6 --- 7 8 # `replace` Function 9 10 `replace` searches a given string for another given substring, and replaces 11 each occurrence with a given replacement string. 12 13 ```hcl 14 replace(string, substring, replacement) 15 ``` 16 17 If `substring` is wrapped in forward slashes, it is treated as a regular 18 expression, using the same pattern syntax as 19 [`regex`](/language/functions/regex). If using a regular expression for the substring 20 argument, the `replacement` string can incorporate captured strings from 21 the input by using an `$n` sequence, where `n` is the index or name of a 22 capture group. 23 24 ## Examples 25 26 ``` 27 > replace("1 + 2 + 3", "+", "-") 28 1 - 2 - 3 29 30 > replace("hello world", "/w.*d/", "everybody") 31 hello everybody 32 ``` 33 34 ## Related Functions 35 36 - [`regex`](/language/functions/regex) searches a given string for a substring matching a 37 given regular expression pattern.