REGEXVAULTv2.0
Localization/Date Formats
Verified Safe

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

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

Php Implementation

Php
<?php
// ISO 8601 Week Date (YYYY-Www-D)
// ReDoS-safe | RegexVault — Localization > Date Formats

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

function validate_iso_8601_week_date_yyyywwwd(string $input): bool {
    return (bool) preg_match(ISO_8601_WEEK_DATE_YYYYWWWD_PATTERN, $input);
}

// Example
var_dump(validate_iso_8601_week_date_yyyywwwd("2024-W03")); // bool(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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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