繁体   English   中英

在python正则表达式中消除逗号和数千位数字之间的空格

[英]eliminate space between comma and thousands digits in python regex

我正在尝试修复一些数据。 它几乎有600万个单词,但是我发现其中一些单词已经用逗号分隔,然后用数字隔开。 例如:

1, 000, 000 cases were produced of this, however, that is not important.

我正在使用:

changed = re.sub(r', \d{3}', r'\d{3}',original.strip())

但这将其更改为:

1,\d{3},\d{3} cases were produced of this, however, that is not important.

因此它可以识别需要更改的内容,而不是需要更改的内容

您需要捕获组中的数字,然后在替换中引用该组。

>>> re.sub(r', (\d{3})', r'\1',original.strip())
'1000000 cases were produced of this, however, that is not important.'

暂无
暂无

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

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