Skip to main content
regexall(pattern, string) applies the RE2 regular expression pattern to string and returns all matches as a list. Each element has the same shape as a single regex result: a string for no-capture-group patterns, or a tuple/object for patterns with capture groups.

Signature

regexall(pattern string, string string) list

Example

Find all GitHub issue references in a commit message and include them in the release notes command:
variable "commit_message" {
  description = "Commit message to scan for issue references"
  type        = string
}

computed "issue_refs" {
  description = "All issue references in the commit"
  expression  = regexall("#[0-9]+", var.commit_message)
}

task "close-issues" {
  description = "Close all issues mentioned in the commit"
  commands = [
    "for ref in ${join(" ", computed.issue_refs)}; do gh issue close $ref; done",
  ]
}
For "Fixes #123 and #456 closes #789", computed.issue_refs becomes ["#123", "#456", "#789"].

Notes

  • regexall returns an empty list when there are no matches. This makes it safe to use in conditions with length.
  • Each match element is a string when the pattern has no capture groups. With capture groups, each element is a tuple of the captured values (or an object for named groups).
  • Use regex when you only need the first match.