Reputation: 8222
I have a string in python, which is in this format:
[NUMBER][OPERATOR][NUMBER][UNNEEDED JUNK]
e.g.:
5+5.[)]1
How could I trim that down to just 5+5
?
EDIT
I forgot to mention, basically, you just need to look for the first non-numeric character after the operator, and crop everything (starting at that point) off.
Upvotes: 1
Views: 1799
Reputation: 118016
This is a simple regular expression:
import re
s = "5+5.[)]1"
s = re.search("\d+\+\d+", s).group()
print(s) # 5+5
Upvotes: 6