re.finditer
re.finditer() returns an iterator of match objects for all matches, giving access to position information.
re.finditer() returns an iterator of match objects for all matches, giving access to position information.
import re
text = "cat bat hat"
for m in re.finditer(r"[cbh]at", text):
print(f"{m.group()} at {m.start()}-{m.end()}")
# cat at 0-3
# bat at 4-7
# hat at 8-11
finditer is memory-efficient for large texts — use instead of findall when you need positions.