Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Golang

`
^P(\\d+Y)?(\\d+M)?(\\d+D)?(T(\\d+H)?(\\d+M)?(\\d+S)?)?$
`

Description

This is made to validate an ISO 8601 input in a Terraform variable validation block:

validation {
    condition     = can(regex("^P(\\d+Y)?(\\d+M)?(\\d+D)?(T(\\d+H)?(\\d+M)?(\\d+S)?)?$", var.value))
    error_message = "The value must be a valid ISO 8601 duration string representing time. (e.g. PT1M, PT1H30M, PT30S, etc.)"
  }
Submitted by anonymous - 2 months ago