I have date strings of the following forms '8 april 2022', '8 april', 'april' and a regex to try and match any of them
re.findall(r"(\d{1,2})?.*(januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december).*(202\d)?", str)
the problem is, it will return ('8', 'april', '') in case of str = '8 april 2022'
so my question is: why does ? ignore 1 occurrence of 202\d when its there?
Thank you.
EDIT. With non greedy .*?
re.findall(r"(\d{1,2}).*?(januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december).*?(202\d)?", str)
it still doesnt capture 2022
EDIT 2. Considering the answers a better question would be: Is there a way of saying 'hey regex 1 occurrence is optional but preferable to 0' ?