Python正则表达式找到所有重叠匹配 在Python中如何检查一个输入是否为数字 windows系统中如何在Python中设置路径 Python正则表达式找到所有重叠匹配 方法1 import re s = "123456789123456789" matches = re.finditer(r'(?=(\d{10}))',s) results = [int(match.group(1)) for match in matches] # results: # [1234567891, # 2345678912, # 3456789123, # 4567891234, # 5678912345, # 6789123456, # 7891234567, # 8912345678, # 9123456789] 方法2 >>> import regex as re >>> s = "123456789123456789" >>> matches = re.findall(r'\d{10}', s, overlapped=True) >>> for match in matches: print match ... 1234567891 2345678912 3456789123 4567891234 5678912345 6789123456 7891234567 8912345678 9123456789 方法3 s = "123456789123456789" n = 10 li = [ s[i:i+n] for i in xrange(len(s)-n+1) ] print '\n'.join(li) 结果 1234567891 2345678912 3456789123 4567891234 5678912345 6789123456 7891234567 8912345678 9123456789 在Python中如何检查一个输入是否为数字 windows系统中如何在Python中设置路径