在前瞻范围内使用捕获组。前瞻捕捉你感兴趣的文本,但是实际匹配在技术上是前瞻之前的零宽度子字符串,因此从技术上讲,这些匹配是不重叠的:
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]


