github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/replace.html.md (about) 1 --- 2 layout: "language" 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 `replace` searches a given string for another given substring, and replaces 13 each occurrence with a given replacement string. 14 15 ```hcl 16 replace(string, substring, replacement) 17 ``` 18 19 If `substring` is wrapped in forward slashes, it is treated as a regular 20 expression, using the same pattern syntax as 21 [`regex`](./regex.html). If using a regular expression for the substring 22 argument, the `replacement` string can incorporate captured strings from 23 the input by using an `$n` sequence, where `n` is the index or name of a 24 capture group. 25 26 ## Examples 27 28 ``` 29 > replace("1 + 2 + 3", "+", "-") 30 1 - 2 - 3 31 32 > replace("hello world", "/w.*d/", "everybody") 33 hello everybody 34 ``` 35 36 ## Related Functions 37 38 - [`regex`](./regex.html) searches a given string for a substring matching a 39 given regular expression pattern.