Reputation: 13
I want to separate numbers from letters. I tried it like this, but it won't work with negative numbers. What do i have to change?
match = re.match(r"([0-9]+(?:.[0-9]+)?)([a-z]+)", "-0.5m", re.I)
number = match.group(1)
letter = = match.group(2)
Upvotes: 0
Views: 242
Reputation: 89897
match = re.match(r"(-?[0-9]+(?:.[0-9]+)?)([a-z]+)", "-0.5m", re.I)
Adds -?
to optionally allow a minus sign at the start of the number.
Upvotes: 3