github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/regexall.html.md (about) 1 --- 2 layout: "language" 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 `regexall` applies a 12 [regular expression](https://en.wikipedia.org/wiki/Regular_expression) 13 to a string and returns a list of all matches. 14 15 ```hcl 16 regexall(pattern, string) 17 ``` 18 19 `regexall` is a variant of [`regex`](./regex.html) and uses the same pattern 20 syntax. For any given input to `regex`, `regexall` returns a list of whatever 21 type `regex` would've returned, with one element per match. That is: 22 23 - If the pattern has no capture groups at all, the result is a list of 24 strings. 25 - If the pattern has one or more _unnamed_ capture groups, the result is a 26 list of lists. 27 - If the pattern has one or more _named_ capture groups, the result is a 28 list of maps. 29 30 `regexall` can also be used to test whether a particular string matches a 31 given pattern, by testing whether the length of the resulting list of matches 32 is greater than zero. 33 34 ## Examples 35 36 ``` 37 > regexall("[a-z]+", "1234abcd5678efgh9") 38 [ 39 "abcd", 40 "efgh", 41 ] 42 43 > length(regexall("[a-z]+", "1234abcd5678efgh9")) 44 2 45 46 > length(regexall("[a-z]+", "123456789")) > 0 47 false 48 ``` 49 50 ## Related Functions 51 52 - [`regex`](./regex.html) searches for a single match of a given pattern, and 53 returns an error if no match is found. 54 55 If Terraform already has a more specialized function to parse the syntax you 56 are trying to match, prefer to use that function instead. Regular expressions 57 can be hard to read and can obscure your intent, making a configuration harder 58 to read and understand.