REGEXVAULTv2.0
Localization/Date Formats
Verified Safe

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

/^((?: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 Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

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

import java.util.regex.Pattern;

public class Iso8601WeekDateYyyywwwdValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^((?:19|20)[0-9]{2})-W(0[1-9]|[1-4][0-9]|5[0-3])(?:-([1-7]))?$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("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 Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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