I am trying to match time using re module
matching is required for the following time format
02:54 pm
02:54pm
02:5407:46pm
02:5407:46 pm
02:5407:46 p.m.
02:5407:46p.m.
2:5407:46p.m.
2:54pm
02:54
I tried using the following pattern
\d{1,2}:\d{2}\s?p?\.?m?\.?
But these 02:5407:46 p.m. formats are shown as split format 02:54 and 07:46 p.m.. I want to consider it as a single pattern and no need to consider separately
>Solution :
There might be a more elegant ways to write this regex, but this one should to the trick:
\d{1,2}:\d{2}(?:\d{2}:\d{2})?\s?p?\.?m?\.?