Avoid matching 4 char years with regex meant for days given as ordinal numbers

Original regex is probably meant to match dates like:
1st Jan 2012
but it also matches
127012025 21.01.2025
because the two chars following the first two can be any character including numbers.
This change excludes numbers there so dates following numbers are parsed correctly.
This commit is contained in:
XstreamGit 2025-01-30 23:59:27 +01:00 committed by shamoon
parent 3314c59828
commit 56bd406c41

View File

@ -41,7 +41,7 @@ DATE_REGEX = re.compile(
r"(\b|(?!=([_-])))(\d{1,2}[\. ]+[a-zéûäëčžúřěáíóńźçŞğü]{3,9} \d{4}|[a-zéûäëčžúřěáíóńźçŞğü]{3,9} \d{1,2}, \d{4})(\b|(?=([_-])))|"
r"(\b|(?!=([_-])))([^\W\d_]{3,9} \d{1,2}, (\d{4}))(\b|(?=([_-])))|"
r"(\b|(?!=([_-])))([^\W\d_]{3,9} \d{4})(\b|(?=([_-])))|"
r"(\b|(?!=([_-])))(\d{1,2}[^ ]{2}[\. ]+[^ ]{3,9}[ \.\/-]\d{4})(\b|(?=([_-])))|"
r"(\b|(?!=([_-])))(\d{1,2}[^ 0-9]{2}[\. ]+[^ ]{3,9}[ \.\/-]\d{4})(\b|(?=([_-])))|"
r"(\b|(?!=([_-])))(\b\d{1,2}[ \.\/-][a-zéûäëčžúřěáíóńźçŞğü]{3}[ \.\/-]\d{4})(\b|(?=([_-])))",
re.IGNORECASE,
)