Input: blah.(2/2)
Desired Output: blah
Input can be "blah.(n/n)" where n can be any single digit number.
How do I use regex to achieve "blah"? This is the regex I currently have which doesn't work:
m = re.sub('[.[0-9] /\ [0-9]]{6}$', '', m)
You need to use regex \.\(\d/\d\)$
>>> import re
>>> str = "blah.(2/2)"
>>> re.sub(r'\.\(\d/\d\)$', '',str)
'blah'
Regex explanation here
Just do this since you will always be looking to split around the .
s = "stuff.(asdfasdfasdf)"
m = s.split('.')[0]
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