github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/string/regex_replace.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: regex_replace - Functions - Configuration Language
     4  description: |-
     5    The regex_replace function searches a given string for another given substring,
     6    and replaces all occurrences with a given replacement string. The substring
     7    argument can be a valid regular expression or a string.
     8  ---
     9  
    10  # `regex_replace` Function
    11  
    12  `regex_replace` searches a given string for another given substring, and
    13  replaces each occurrence with a given replacement string. The substring
    14  argument can be a valid regular expression or a string.
    15  
    16  ```hcl
    17  regex_replace(string, substring, replacement)
    18  ```
    19  
    20  `substring` should not be wrapped in forward slashes, it is always treated as a
    21  regular expression. The `replacement` string can incorporate captured strings
    22  from the input by using an `$n` or `${n}` sequence, where `n` is the index or
    23  name of a capture group.
    24  
    25  ## Examples
    26  
    27  ```shell-session
    28  > regex_replace("hello world", "world", "everybody")
    29  hello everybody
    30  
    31  
    32  > regex_replace("hello world", "w.*d", "everybody")
    33  hello everybody
    34  
    35  > regex_replace("-ab-axxb-", "a(x*)b", "$1W)
    36  ---
    37  
    38  > regex_replace("-ab-axxb-", "a(x*)b", "${1}W")
    39  -W-xxW-
    40  ```
    41  
    42  ## Related Functions
    43  
    44  - [`replace`](/docs/job-specification/hcl2/functions/string/replace) searches a given string for another given
    45    substring, and replaces all occurrences with a given replacement string.