REGEXVAULTv2.0
Localization/Time Formats
Verified Safe

IANA Timezone Identifier Regex for Go

/^(?:Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific|Etc)/[A-Za-z0-9_+\-]+(?:/[A-Za-z0-9_+\-]+)?$/

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching iana timezone identifier, ported and verified for Go. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// IANA Timezone Identifier
// ReDoS-safe | RegexVault — Localization > Time Formats

package validation

import "regexp"

var ianaTimezoneIdentifierRe = regexp.MustCompile(`^(?:Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific|Etc)/[A-Za-z0-9_+\-]+(?:/[A-Za-z0-9_+\-]+)?$`)

func ValidateIanaTimezoneIdentifier(s string) bool {
    return ianaTimezoneIdentifierRe.MatchString(s)
}

// Example
// fmt.Println(ValidateIanaTimezoneIdentifier("America/New_York")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
America/New_YorkEST
Europe/LondonUTC+8
Asia/SingaporeNew_York
Asia/KolkataAmerica/New York
Australia/SydneyAmerica/
Pacific/AucklandUS/Eastern
Etc/UTC

When to use this pattern

This pattern is drawn from the Localization > Time Formats category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

IANA zone names can change when countries change their timezone rules. The tzdb is updated multiple times per year. Always use the latest version in your runtime.

Technical Notes

IANA timezone database (TZDB/Olson database) is the global standard. Format: Area/Location or Area/Location/Subzone. Etc/* zones are for UTC offsets. US/*, Canada/*, US/Eastern are deprecated aliases.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern