[Python-ideas] Re module repeat
Georg Brandl
g.brandl at gmx.net
Mon Aug 1 07:12:38 CEST 2011
Am 01.08.2011 02:36, schrieb Christopher King:
> Dear Idealists,
> I notice that when you do use the re module grouping, that it only tells you
> what it matched last:
>
> Dumb Real Python Code:
>>>> import re
>>>> match=re.search('^(?P<letter>[a-z])*$', 'abcz')
>>>> match.groupdict()
> {'letter': '0'}
> What happened to all the other matches. Now here is a cool idea.
>
> Cool Improved Python Code
>>>> import re
>>>> match=re.search('^(?P<letter>[a-z])*$', 'abcz')
>>>> match.groupdict()
> {'number': '0'}
> {'letter.0':'a', 'letter.1':'b', 'letter.2':'c', 'letter.3':'z'}
The "regex" module by Matthew Barnett already supports this:
https://code.google.com/p/mrab-regex-hg/
Georg
More information about the Python-ideas
mailing list