Skip to content

1500 - Regex Patterns

Named regex patterns for validation. This is an example of a MAML document.

maml
# Validation regex patterns
{
  email: """
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
""" # RFC 5322 simplified
  phone: """
^\+?[1-9]\d{1,14}$
""" # E.164 format
  uuid: """
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
"""
  slug: """
^[a-z0-9]+(?:-[a-z0-9]+)*$
"""

  # Semantic versioning
  semver: """
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?$
"""
  ipv4: """
^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$
"""
  hex_color: """
^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
"""

  # URL patterns
  url: """
^https?://[^\s/$.?#].[^\s]*$
"""
}

See Also