我正在学习python,我有一个问题,我想匹配这样的东西:
主题: 1234567890
匹配我想要的:1 then 234 then 567 then 890
1,234,567,890
我试过的是:
(\d)(\d{3})+
不工作
https://regex101.com/r/AaWroO/1/
有什么简单的方法(不那么复杂的正则表达式,因为我不是那么专家,我是一个初学者)来做这件事?
发布于 2017-09-01 18:48:14
您可以使用替换来匹配单词边界后的数字或任意3位数字:
>>> s = '1234567890'
>>> print re.findall(r'\b\d|\d{1,3}', s)
['1', '234', '567', '890']
RegEx分手:
\b\d
:在单词边界后匹配一个数字|
:或\d{1,3}
:匹配任意1到3位数字https://stackoverflow.com/questions/46006302
复制相似问题