简体   繁体   中英

separating numbers from letters; python

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)
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM