[Tutor] Python re without string consumption
Jacob Abraham
jakieabraham at yahoo.com
Thu Jan 25 09:16:25 CET 2007
Hi Danny Yoo,
I would like to thank you for the solution and
the helper funtion that I have written is as follows. But I do hope
that future versions of Python include a regular expression syntax to
handle such cases simply because this method seems very process and
memory intensive. I also notice that fall_back_len is a very crude
solution.
def searchall(expr, text, fall_back_len=0):
while True:
match = re.search(expr, text)
if not match:
break
yield match
end = match.end()
text = text[end-fall_back_len:]
for match in searchall("abca", "abcabcabca", 1):
print match.group()
Thanks Again.
Jacob Abraham
____________________________________________________________________________________
Get your own web address.
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
More information about the Tutor
mailing list