简体   繁体   English

如果我使用re.findall如何注册以便不分开

[英]if i use re.findall How to register in order not to separate the point

I need to extract the numbers from this string : 我需要从此字符串中提取数字:

str="((8,52),(30,52),2,0.5)"

if i used : re.findall('\\d+',str) i well get : 如果我使用过: re.findall('\\d+',str)我很好地得到:

['20', '48', '48', '48', '2', '0', '5']

There is a problem with 0.5 0.5有问题

How do I get 0.5 together to get : 我如何一起获得0.5来获得:

['20', '48', '48', '48', '2', '0.5']

re.findall("\\d+\\.\\d+|\\d+",str)

正则表达式中的第一组将找到小数点两侧的数字,第二组将找到整数。

Use a numeric parse standard (?:\\d+(?:\\.\\d*)?|\\.\\d+) 使用数字解析标准(?:\\d+(?:\\.\\d*)?|\\.\\d+)
Covers all cases: 涵盖所有情况:

5 5
5. 5,
5.1 5.1
.1 .1

re.findall(r'\d+\.?\d*',str)

输出:

['8', '52', '30', '52', '2', '0.5']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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