正则表达式查找6或7位数字
我在用Python的re模块写正则表达式,得到了这个结果:
In [156]: re.findall(r'.*\D(\d{6,7})\D.*', ' f123456 f1234567 ')
Out[156]: ['1234567']
...但是我想要这个结果:
Out[156]: ['123456', '1234567']
我不知道该怎么写这个正则表达式。你能帮我吗?
1 个回答
8
简化正则表达式
In [5]: re.findall(r'\d{6,7}', ' f123456 f1234567 ')
Out[5]: ['123456', '1234567']