How to check if text/string has (number:number-number) format in Python?
An example is (7:10-9)
I think I need to use Regex?
Yes, that would be the easiest. Example:
In [1]: import re
In [2]: re.match('\(\d+:\d+-\d+\)', '(7:10-9)')
Out[2]: <_sre.SRE_Match at 0x24655e0>
In [3]: re.match('\(\d+:\d+-\d+\)', '(7)')
In [4]:
As a function:
def match(s):
return bool(re.match('\(\d+:\d+-\d+\)', s))
Don't forget to look through the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With