Greedy regex pattern in month token causes parsing failures for double-digit months
Bug Description The current regex pattern for the month token M uses a greedy left-to-right matching approach that fails to correctly parse double-digit months (10, 11, 12) in date strings.
Steps to Reproduce: use locale as chinese (zh_TW) and provide shorthand month notations as [ '1' '2', '3', ... '12' ]
Create a date input with format Y-M-d Parse the date string "2025-12-24" Observe the parsing result Expected Result:
Year: 2025 Month: 12 Day: 24 Actual Result:
Year: 2025 Month: 1 (incorrect - matches first character of "12") Day: 24
Root Cause The regex engine processes alternatives from left to right. In the pattern (1|2|3|4|5|6|7|8|9|10|11|12):
For input "12": Matches "1" first and stops For input "10": Matches "1" first and stops For input "11": Matches "1" first and stops
Proposed Solution Update the month token regex to match longer patterns first: // Current (problematic) "M": "(1|2|3|4|5|6|7|8|9|10|11|12)"
// Proposed fix "M": "(1[0-2]|[1-9])"
This pattern: First tries to match 1[0-2] (months 10, 11, 12) Falls back to [1-9] (months 1-9)
Impact: This bug affects: Internationalization for locales using numeric month representations Form validation and user input processing Calendar widget date selection
Source: flatpickr/flatpickr