• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Packer
  • Install
  • Tutorials
  • Documentation
  • Guides
  • Plugins
  • Try Cloud(opens in new tab)
  • Sign up
Packer Home

Documentation

Skip to main content
  • Documentation
  • HCP Packer

  • Terminology
    • Overview
      • Overview
        • Overview
          • chomp
          • format
          • formatlist
          • indent
          • join
          • lower
          • replace
          • regex_replace
          • regex
          • regexall
          • split
          • strrev
          • substr
          • title
          • trim
          • trimprefix
          • trimsuffix
          • trimspace
          • upper
      • Variables
      • Locals
      • Contextual Variables
      • Data Sources
      • Path Variables
      • Syntax
      • Only Except
      • Expressions
      • JSON Syntax


  • Installing Packer
  • Configuring Packer

  • Integration Program

  • Debugging

  • Resources

  • Tutorial Library
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  1. Developer
  2. Packer
  3. Documentation
  4. Templates
  5. HCL Templates
  6. Functions
  7. String Functions
  8. regexall
  • Packer
  • v1.7.x
  • v1.6.x
  • v1.5.x

ยปregexall Function

regexall applies a regular expression to a string and returns a list of all matches.

regexall(pattern, string)

regexall is a variant of regex and uses the same pattern syntax. For any given input to regex, regexall returns a list of whatever type regex would've returned, with one element per match. That is:

  • If the pattern has no capture groups at all, the result is a list of strings.
  • If the pattern has one or more unnamed capture groups, the result is a list of lists.
  • If the pattern has one or more named capture groups, the result is a list of maps.

regexall can also be used to test whether a particular string matches a given pattern, by testing whether the length of the resulting list of matches is greater than zero.

Examples

> regexall("[a-z]+", "1234abcd5678efgh9")
[
  "abcd",
  "efgh",
]

> length(regexall("[a-z]+", "1234abcd5678efgh9"))
2

> length(regexall("[a-z]+", "123456789")) > 0
false

Related Functions

  • regex searches for a single match of a given pattern, and returns an error if no match is found.

If Packer already has a more specialized function to parse the syntax you are trying to match, prefer to use that function instead. Regular expressions can be hard to read and can obscure your intent, making a configuration harder to read and understand.

Edit this page on GitHub

On this page

  1. regexall Function
  2. Examples
  3. Related Functions
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)