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分割(“”)
和getres[0]
和res[-1]
你能分享一些实际数据吗?他是谁?@MohitC我的英语不好。Thanks@WiktorStribiżew