github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/replace.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "replace - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-string-replace" 5 description: |- 6 The replace function searches a given string for another given substring, 7 and replaces all occurrences with a given replacement string. 8 --- 9 10 # `replace` Function 11 12 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 13 earlier, see 14 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 15 16 `replace` searches a given string for another given substring, and replaces 17 each occurrence with a given replacement string. 18 19 ```hcl 20 replace(string, substring, replacement) 21 ``` 22 23 If `substring` is wrapped in forward slashes, it is treated as a regular 24 expression, using the same pattern syntax as 25 [`regex`](./regex.html). If using a regular expression for the substring 26 argument, the `replacement` string can incorporate captured strings from 27 the input by using an `$n` sequence, where `n` is the index or name of a 28 capture group. 29 30 ## Examples 31 32 ``` 33 > replace("1 + 2 + 3", "+", "-") 34 1 - 2 - 3 35 36 > replace("hello world", "/w.*d/", "everybody") 37 hello everybody 38 ``` 39 40 ## Related Functions 41 42 - [`regex`](./regex.html) searches a given string for a substring matching a 43 given regular expression pattern.