On Tue, May 29, 2012 at 7:33 PM, Roy Smith <r...@panix.com> wrote: > I have a long string (possibly 100s of Mbytes) that I want to search for > regex matches. re.finditer() is *almost* what I want, but the problem > is that it returns matching strings. What I need is a list of offsets > in the string where the regex matched. Thus: > > s = "this is a string" > find("is", s) => [2, 5] > > Is there anything that does this?
s = "this is a string" pattern = re.compile("is") pos = 0 while True: match = pattern.search(s, pos) if match: print(match.start()) pos = match.start() + 1 else: break Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list