From 3bf37b936f7757a6db880635b8de514dcc9c47e2 Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 10 Jul 2025 16:50:04 -0500 Subject: [PATCH] fix: regex greedy pattern stops early when parsing shorter unit markers --- src/relative.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/relative.rs b/src/relative.rs index b004d2d..c5848e0 100644 --- a/src/relative.rs +++ b/src/relative.rs @@ -17,13 +17,13 @@ impl Months for Duration { lazy_static! { static ref FULL_RELATIVE_PATTERN: Regex = Regex::new(concat!( "(?[-+])?", - r"(?:(?\d+)\s?(?:y|yrs?|years?))?", - r"(?:(?\d+)\s?(?:mon|months?))?", - r"(?:(?\d+)\s?(?:w|wks?|weeks?))?", - r"(?:(?\d+)\s?(?:d|days?))?", - r"(?:(?\d+)\s?(?:h|hrs?|hours?))?", - r"(?:(?\d+)\s?(?:m|mins?|minutes?))?", - r"(?:(?\d+)\s?(?:s|secs?|seconds?))?" + r"(?:(?\d+)\s?(?:years?|yrs?|y)\s*)?", + r"(?:(?\d+)\s?(?:months?|mon)\s*)?", + r"(?:(?\d+)\s?(?:weeks?|wks?|w)\s*)?", + r"(?:(?\d+)\s?(?:days?|d)\s*)?", + r"(?:(?\d+)\s?(?:hours?|hrs?|h)\s*)?", + r"(?:(?\d+)\s?(?:minutes?|mins?|m)\s*)?", + r"(?:(?\d+)\s?(?:seconds?|secs?|s)\s*)?" )) .unwrap(); }