Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将数字与字母分开。我试过这样,但它不适用于负数。我必须改变什么?
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)
添加-?以可选地允许在数字开头使用减号。
-?