我有一个如下所示的文本文件:
15372185 ChocolateBiscuit 1.20
13281038 AppleJuice 1.50
26419633 TomatoSoup 2.10
74283187 SpringRolls 0.90
基本上,我想匹配任何有小数点的数字(这是每行的最后一个数字)。要找到开头的8位数字和描述,我有:
codes = re.findall(r'\d{8}', fread)
details = re.findall(r'\b[A-Z][a-z]*[A-Z][a-z]*', fread)
我假设我用类似的方法来找出所有带小数点的数字?我只是不明白我该怎么做。你知道吗
'获取要匹配的文本
'创建一个匹配字符串,包括接受像“.23”这样的数字'
'获取字符串中的所有匹配项。你知道吗
'遍历每个组并获得第3项,即十进制数。你知道吗
可以使用
For[...]
返回所需的值,从Item()1到3(1是8位数字,2是名称,3是小数)。或者整个团队都能得到。我的示例代码中使用了第3项。所有代码:(测试和工作)
结果:
搜索小数点周围的任意数字,用边界括起来。你知道吗
如果您还需要捕获.23这样的数字,请使用:
相关问题 更多 >
编程相关推荐