REGEXVAULTv2.0
Localization/Date Formats
Verified Safe

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

/^((?: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 Python. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.

Python Implementation

Python
# ISO 8601 Week Date (YYYY-Www-D)
# ReDoS-safe | RegexVault — Localization > Date Formats

import re

iso_8601_week_date_yyyywwwd_pattern = re.compile(r'^((?:19|20)[0-9]{2})-W(0[1-9]|[1-4][0-9]|5[0-3])(?:-([1-7]))?$')

def validate_iso_8601_week_date_yyyywwwd(value: str) -> bool:
    return bool(iso_8601_week_date_yyyywwwd_pattern.fullmatch(value))

# Example
print(validate_iso_8601_week_date_yyyywwwd("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 Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. 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