Determine if a string is a time with a python regular expression

I want to judge the time from 0:00 to 23:59 with a regular expression. I want to support single-digit hours and double-digit hours and minutes.

If it is below, 29:59 will also be judged as the time.

re.match(r'([0-2]?[0-9]):([0-5]?[0-9])', '29:59')
<re.Match object; span=(0, 5), match='29:59'>

If it was as follows, it worked as expected.

re.match(r'([0-1]?[0-9]|2[0-3]):([0-5]?[0-9])', '23:59')
<re.Match object; span=(0, 5), match='23:59'>
re.match(r'([0-1]?[0-9]|2[0-3]):([0-5]?[0-9])', '24:00')

If there is another good way, please comment!

Recommended Posts

Determine if a string is a time with a python regular expression
Make one repeating string with a Python regular expression.
String replacement with Python regular expression
Regular expression manipulation with Python
Check if the string is a number in python
When writing an if statement with a regular expression
[Python] What is a with statement?
Determine if the string is formatable
Get the matched string with a regular expression and reuse it when replacing on Python3
I tried to make a regular expression of "time" using Python
Determine if standard output is piped when running a Python script
[Python] A function that searches the entire string with a regular expression and retrieves all matching strings.
Get the number of searches with a regular expression. SeleniumBasic VBA Python
[Python3] A story stuck with time zone conversion
Decrypt a string encrypted on iOS with Python
A python lambda expression ...
Regular expression with pymongo
python regular expression memo
Regular expression in Python
Regular expression in Python
How to convert / restore a string with [] in python
Basics of Python learning ~ What is a string literal? ~
python> check NoneType or not> if a == None:> if a is None:
A python regular expression, or a memo of a match object
What is God? Make a simple chatbot with python
Implement a circular expression binary search in Python. There is a comparison with a simple full search.
Change the string to be replaced according to the matched string by replacing with Python regular expression
Quickly take a query string with API Gateway-> Lambda (Python)
[Python] Use a string sequence
I made a package to filter time series with python
Python 處 處 regular expression Notes
[python] Reverse with slices! !! (There is also a commentary on slices!)
Is this string a decimal?
A memo when face is detected with Python + OpenCV quickly
Determine prime numbers with python
Addition with Python if statement
When converting a string (a-> b) in Python, which is faster, if statement or dictionary type?
Python list is not a list
Make a fortune with Python
Execution time measurement with Python With
Create a message corresponding to localization with python translation string
Create a directory with python
Time synchronization (Windows) with Python
String format with Python% operator
What is a python map?
In the python dictionary, if a non-existent key is accessed, initialize it with an arbitrary value
Convert to a string while outputting standard output with Python subprocess
Python will fail if there is a space after the backslash
If you know Python, you can make a web application with Django
[Introduction to Python] How to split a character string with the split function
I tried to make a regular expression of "amount" using Python
[Python 3.8 ~] How to define a recursive function smartly with a lambda expression
A python regular expression, str and unicode that are sober and addictive
[Python] Execution time when a function is entered in a dictionary value
Delete a particular character in Python if it is the last
Try to extract a character string from an image with Python3
I tried to make a regular expression of "date" using Python
I tried to find out if ReDoS is possible with Python
[Golang] Check if a specific character string is included in the character string
A memo for when pip3 is installed with python2.7 for some reason
[Python] What is a zip function?