Python正则表达式将数字转换为字符串

Python正则表达式将数字转换为字符串,python,regex,Python,Regex,有这样一个字符串表达式 example, example, -1,2 example, example/example, 9,9 -1,2和9,9是浮点数 在这里如何分隔字符串和浮点语句 尝试下面的语句时,将字符串和浮点语句分开。但是,表达式中存在问题,例如-1,2-9,0 import re ... print(re.split(r'\s+(?=\d)|(?<=\d)\s+', txt)) output: ['example, example -1,0'] ['example,

有这样一个字符串表达式

example, example, -1,2
example, example/example, 9,9
-1,2和9,9是浮点数

在这里如何分隔字符串和浮点语句

尝试下面的语句时,将字符串和浮点语句分开。但是,表达式中存在问题,例如-1,2-9,0

import re

...

print(re.split(r'\s+(?=\d)|(?<=\d)\s+', txt))


output:
['example, example -1,0']
['example, example/example', '9,9']

....
重新导入
...

打印(re.split)(r'\s+(?=\d)|(?你实际上可以使用
res=“example,example,-1,2.”分割(“”)并获得
res[0]
res[-1]
你能分享一些实际数据吗?谁是“他”…@MohitC我的英语不好。Thanks@WiktorStribiżewYou实际上可以使用
res=“example,example,-1,2”.r分割(“”)
和get
res[0]
res[-1]
你能分享一些实际数据吗?他是谁?@MohitC我的英语不好。Thanks@WiktorStribiżew