它必须符合以下条件:
'42'
'1,234'
"6368745"
但不是以下内容:
'12,34,567'(逗号之间只有两位数)
'1234'(缺少逗号)
我在python 3中编写了以下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())
Run Code Online (Sandbox Code Playgroud)
小智 6
试试这个:
^(\d{1,3})(,\d{3})*$
Run Code Online (Sandbox Code Playgroud)
https://regex101.com/r/Dy83Jv/1