A vote for re scanner

Wade Leftwich wade at lightlink.com
Sun Nov 16 08:22:00 EST 2003


"Fredrik Lundh" <fredrik at pythonware.com> wrote in message news:<mailman.765.1068940219.702.python-list at python.org>...
> Wade Leftwich wrote:
> 
> > >>> regex = re.compile(r'(?P<before>.)a(?P<after>.)')
> > >>> s = '1ab2ac3ad'
> > >>> for m in CoolerScanner(regex, s):
> > ... print m.group('before'), m.group('after')
> > ...
> > 1 b
> > 2 c
> > 3 d
>  
> >>> regex = re.compile(r'(?P<before>.)a(?P<after>.)')
> >>> s = '1ab2ac3ad'
> >>> for m in regex.finditer(s):
> ...     print m.group('before'), m.group('after')
> ...
> 1 b
> 2 c
> 3 d
> 
> </F>

There I go, reimplementing the wheel again. Guess I didn't pay enough
attention to "What's New In 2.2". Thanks for the pointer. It appears
we don't need that scanner() method after all.

However, from my point of view it was a good exercise, because now I
know how easy it is to make an iterator.

Thanks again

-- Wade




More information about the Python-list mailing list