Regex to Match ISO Week Number Dates
Validate ISO 8601 week date strings in the format YYYY-Www or YYYY-Www-D. Matches week numbers from W01 to W53 with optional day number. Free regex tester.
Regular Expression
/^\d{4}-W(?:0[1-9]|[1-4][0-9]|5[0-3])(?:-[1-7])?$/
Token Breakdown
| Token | Description |
|---|---|
| ^ | Anchors at the start of the string (or line in multiline mode) |
| \d | Matches any digit (0-9) |
| {4} | Matches exactly 4 times |
| - | Matches the literal character '-' |
| W | Matches the literal character 'W' |
| (?: | Start of non-capturing group |
| 0 | Matches the literal character '0' |
| [1-9] | Character class — matches any one of: 1-9 |
| | | Alternation — matches the expression before OR after the pipe |
| [1-4] | Character class — matches any one of: 1-4 |
| [0-9] | Character class — matches any one of: 0-9 |
| | | Alternation — matches the expression before OR after the pipe |
| 5 | Matches the literal character '5' |
| [0-3] | Character class — matches any one of: 0-3 |
| ) | End of group |
| (?: | Start of non-capturing group |
| - | Matches the literal character '-' |
| [1-7] | Character class — matches any one of: 1-7 |
| ) | End of group |
| ? | Makes the preceding element optional (zero or one times) |
| $ | Anchors at the end of the string (or line in multiline mode) |
Detailed Explanation
This regex validates ISO 8601 week date strings, which represent dates by year, week number, and optionally day of the week. Here is the token-by-token breakdown:
^ — Anchors the match at the start of the string.
\d{4} — Matches exactly four digits for the ISO year. Note that the ISO week-numbering year may differ from the calendar year for dates near the year boundary.
-W — Matches the literal -W separator that identifies this as a week date format. The W prefix distinguishes week dates from ordinal dates and calendar dates.
(?:0[1-9]|[1-4][0-9]|5[0-3]) — A non-capturing group matching the week number from 01 to 53. 0[1-9] matches weeks 01-09, [1-4][0-9] matches weeks 10-49, and 5[0-3] matches weeks 50-53. Most years have 52 weeks, but some ISO years have 53 weeks.
(?:-[1-7])? — An optional non-capturing group for the day of the week. When present, it consists of a hyphen followed by a digit from 1 (Monday) to 7 (Sunday). ISO 8601 defines Monday as the first day of the week.
$ — Anchors the match at the end of the string.
No flags are used since this validates a single week date string.
ISO week dates are used in business and industrial planning, particularly in European countries. They are common in manufacturing schedules, fiscal reporting, and project management. Examples include: 2024-W01 (first week of 2024), 2024-W52-5 (Friday of week 52), and 2023-W53 (the rare 53rd week).
This pattern is useful for date validation in scheduling systems, timesheet applications, and data import tools that handle ISO week dates.
Example Test Strings
| Input | Expected |
|---|---|
| 2024-W01 | Match |
| 2024-W52-5 | Match |
| 2024-W53 | Match |
| 2024-W00 | No Match |
| 2024-W54 | No Match |
| 2024-W01-8 | No Match |
Try It — Interactive Tester
48 charsFlags: noneMatches: 0Ctrl+Shift+C to copy regex
Related Regex Patterns
Regex to Match YYYY-MM-DD Dates
/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/
Regex to Match ISO 8601 DateTime
/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d{1,3})?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/
Regex to Match Timezone Offsets
/^(?:Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9])$/
Regex to Match ISO 8601 Duration Format
/^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(?:T(?!$)(\d+H)?(\d+M)?(\d+(?:\.\d+)?S)?)?$/