Reputation: 1534
I am looking to match the following time format
[hours]:[minutes]:[seconds]
[minutes]:[seconds]
[total_seconds]
My attempt was
([0-9]{1,2}:)?([0-9]{1,2}:)?([0-9]+)
But it fails for [minutes]:[seconds]
, 23:45
matches [hours]:[minutes]:[seconds]
with minutes as empty.
Upvotes: 1
Views: 62
Reputation: 78
This regex should work:
regex=r"(^\d{1,2}:\d{1,2}$)|(^\d{1,2}:\d{1,2}:\d{1,2}$)|(^\d+$)"
Upvotes: 1