github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/regexall.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "regexall - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-string-regexall"
     5  description: |-
     6    The regex function applies a regular expression to a string and returns a list of all matches.
     7  ---
     8  
     9  # `regexall` Function
    10  
    11  -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
    12  earlier, see
    13  [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
    14  
    15  `regexall` applies a
    16  [regular expression](https://en.wikipedia.org/wiki/Regular_expression)
    17  to a string and returns a list of all matches.
    18  
    19  ```hcl
    20  regexall(pattern, string)
    21  ```
    22  
    23  `regexall` is a variant of [`regex`](./regex.html) and uses the same pattern
    24  syntax. For any given input to `regex`, `regexall` returns a list of whatever
    25  type `regex` would've returned, with one element per match. That is:
    26  
    27  - If the pattern has no capture groups at all, the result is a list of
    28    strings.
    29  - If the pattern has one or more _unnamed_ capture groups, the result is a
    30    list of lists.
    31  - If the pattern has one or more _named_ capture groups, the result is a
    32    list of maps.
    33  
    34  `regexall` can also be used to test whether a particular string matches a
    35  given pattern, by testing whether the length of the resulting list of matches
    36  is greater than zero.
    37  
    38  ## Examples
    39  
    40  ```
    41  > regexall("[a-z]+", "1234abcd5678efgh9")
    42  [
    43    "abcd",
    44    "efgh",
    45  ]
    46  
    47  > length(regexall("[a-z]+", "1234abcd5678efgh9"))
    48  2
    49  
    50  > length(regexall("[a-z]+", "123456789")) > 0
    51  false
    52  ```
    53  
    54  ## Related Functions
    55  
    56  - [`regex`](./regex.html) searches for a single match of a given pattern, and
    57    returns an error if no match is found.
    58  
    59  If Terraform already has a more specialized function to parse the syntax you
    60  are trying to match, prefer to use that function instead. Regular expressions
    61  can be hard to read and can obscure your intent, making a configuration harder
    62  to read and understand.