May-14-2020, 02:39 PM
>>> import re >>> pattern = re.compile('ab') >>> matcher = pattern.finditer('zxaababaababa') >>> for match in matcher: ... print("starting index ", str(match.start()).ljust(4,' ') + " End index ", str(match.end()).ljust(4,' ')) ... starting index 3 End index 5 starting index 5 End index 7 starting index 8 End index 10 starting index 10 End index 12