我正在处理使用空格作为千位分隔符的文本,例如 400 或 40 000 或 40 000 000 或 4 000 000 000。我需要识别字符串中的数字。一旦确定,有许多选项可以重新格式化数字。我是正则表达式的新手。这不起作用:
import re
line = '40) He had 120 hours to increase from 40 000 units to 20 000 000.'
regex = re.compile("(\d+ *\d+)")
re.findall(regex, line)
['40', '120', '40 000', '20 000', '000']