> >>> re.split(r'@#', s)
> ['', ' This ', ' is a ', '', ' test ']
> >>> [g.group(1) for g in re.finditer(r'(.*?)(?:@#|$)', s)]
> ['', ' This ', ' is a ', '', ' test ', '']
If it's duplicating the behaviour of split, but returning an iterator
instead, how about avoiding hacking around with messy regexes and use
something like the following generator:
def splititer(pattern, string):
posn = 0
while True:
m = pattern.search(string, posn)
if not m:
break
yield string[posn:m.start()]
posn = m.end()
--
http://mail.python.org/mailman/listinfo/python-list