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