REGEXVAULTv2.0
Localization/Date Formats
Verified Safe

ISO 8601 Week Date (YYYY-Www-D) Regex for Go

/^((?:19|20)[0-9]{2})-W(0[1-9]|[1-4][0-9]|5[0-3])(?:-([1-7]))?$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching iso 8601 week date (yyyy-www-d), 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
// ISO 8601 Week Date (YYYY-Www-D)
// ReDoS-safe | RegexVault — Localization > Date Formats

package validation

import "regexp"

var iso8601WeekDateYyyywwwdRe = regexp.MustCompile(`^((?:19|20)[0-9]{2})-W(0[1-9]|[1-4][0-9]|5[0-3])(?:-([1-7]))?$`)

func ValidateIso8601WeekDateYyyywwwd(s string) bool {
    return iso8601WeekDateYyyywwwdRe.MatchString(s)
}

// Example
// fmt.Println(ValidateIso8601WeekDateYyyywwwd("2024-W03")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
2024-W032024-W00
2024-W03-12024-W54
2024-W52-72024-W03-0
2020-W532024-W03-8
2024-W01-52024W03
2024-W3

When to use this pattern

This pattern is drawn from the Localization > Date 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

ISO week year ≠ calendar year at year boundaries. 2024-W01-1 (Monday of week 1 of 2024) is actually December 31, 2023 in the calendar. Use isoweek-aware date libraries.

Technical Notes

ISO week year may differ from calendar year — the first week of the year contains the first Thursday. Week 1 starts from Monday. Day: 1=Monday, 7=Sunday. Some years have 53 weeks (ISO 8601 long years).

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