I tried this
pattern_time = (
r"\b\d{1,2}([: .]?)(\d{2})?(\s?)((P|p)?)(.?)((M|m)?)(.?)((next|this)?)(\s?)((tomorrow|today|day|evening|morning|(mid?)night|((after|before)?)(noon))?)\b"
)
test_string = "The meeting is at 3pm today or 5 tomorrow or 7 this afternoon or 00:00 midnight. Let's meet at 11.30 p.M. We can also do 8:45 pm or 1200 hr or 00hr."
matches = re.findall(pattern_time, test_string, re.IGNORECASE)
print(matches)
and obtained in python
[('', '', '', 'p', 'p', 'm', '', '', ' ', '', '', '', 'today', 'today', '', '', '', ''), (' ', '', '', '', '', '', '', '', '', '', '', '', 'tomorrow', 'tomorrow', '', '', '', ''), (' ', '', '', '', '', '', '', '', '', 'this', 'this', ' ', 'afternoon', 'afternoon', '', 'after', 'after', 'noon'), (':', '00', ' ', '', '', '', '', '', '', '', '', '', 'midnight', 'midnight', 'mid', '', '', ''), ('.', '30', ' ', 'p', 'p', '.', 'M', 'M', '.', '', '', ' ', '', '', '', '', '', ''), (':', '45', ' ', 'p', 'p', 'm', '', '', ' ', '', '', '', '', '', '', '', '', ''), ('', '00', ' ', '', '', 'h', '', '', 'r', '', '', ' ', '', '', '', '', '', ''), ('', '', '', '', '', 'h', '', '', 'r', '', '', '', '', '', '', '', '', '')]
but regextest is showing that it is correct.
How can we rectify this in Python?
Thank you for your help.