fix: regex greedy pattern stops early when parsing shorter unit markers

This commit is contained in:
2025-07-10 16:50:04 -05:00
parent a6fe3995c5
commit 3bf37b936f

View File

@@ -17,13 +17,13 @@ impl Months for Duration {
lazy_static! { lazy_static! {
static ref FULL_RELATIVE_PATTERN: Regex = Regex::new(concat!( static ref FULL_RELATIVE_PATTERN: Regex = Regex::new(concat!(
"(?<sign>[-+])?", "(?<sign>[-+])?",
r"(?:(?<year>\d+)\s?(?:y|yrs?|years?))?", r"(?:(?<year>\d+)\s?(?:years?|yrs?|y)\s*)?",
r"(?:(?<month>\d+)\s?(?:mon|months?))?", r"(?:(?<month>\d+)\s?(?:months?|mon)\s*)?",
r"(?:(?<week>\d+)\s?(?:w|wks?|weeks?))?", r"(?:(?<week>\d+)\s?(?:weeks?|wks?|w)\s*)?",
r"(?:(?<day>\d+)\s?(?:d|days?))?", r"(?:(?<day>\d+)\s?(?:days?|d)\s*)?",
r"(?:(?<hour>\d+)\s?(?:h|hrs?|hours?))?", r"(?:(?<hour>\d+)\s?(?:hours?|hrs?|h)\s*)?",
r"(?:(?<minute>\d+)\s?(?:m|mins?|minutes?))?", r"(?:(?<minute>\d+)\s?(?:minutes?|mins?|m)\s*)?",
r"(?:(?<second>\d+)\s?(?:s|secs?|seconds?))?" r"(?:(?<second>\d+)\s?(?:seconds?|secs?|s)\s*)?"
)) ))
.unwrap(); .unwrap();
} }