必须符合以下条件:
'42'
“1234”
'6368745'
但不包括以下内容:
'12,34567'(逗号之间只有两个数字)
“1234”(缺少逗号)
我用python3编写了以下python程序。我做错什么了?它给了AttributeError
import re
numRegx = re.compile(r"""^
(\d{1,3}(\,))? # optional first three digits and comma (1,)
((d{3})(\,))* # optional Second three digits and comma (345,)
\d{3}$ # Last three digits (456)
""", re.VERBOSE)
mo = numRegx.search('1,345,456')
print(mo.group())
这应该行得通。在
正则表达式:
JavaScript代码:
输入:
输出:
参见:https://regex101.com/r/oq67pb/2
这里的答案可能对你的需要有用
这是对类似问题的公认答案:
Regular expression to match numbers with or without commas and decimals in text
试试这个:
https://regex101.com/r/Dy83Jv/1
相关问题 更多 >
编程相关推荐