Regexp : repeated group identification

candide candide at free.invalid
Wed Dec 14 07:57:33 EST 2011


Le 14/12/2011 12:34, Vlastimil Brom a écrit :

> "If a group is contained in a part of the pattern that matched
> multiple times, the last match is returned."
>

I missed this point, your answer matches my question ;) thanks.


> If you need to work with the content captured in the repeated group,
> you may check the new regex implementation:
> http://pypi.python.org/pypi/regex
>
> Which has a special "captures" method of the match object for this
> (beyond many other improvements):
>
>>>> import regex
>>>> m=regex.match('(Spam\d)+', 'Spam4Spam2Spam7Spam8')
>>>> m.captures(1)
> ['Spam4', 'Spam2', 'Spam7', 'Spam8']
>>>>
>


Thanks for the reference and the example. I didn't know of this 
reimplementation, hoping it offers the Aho-Corasick algorithm allowing 
multiple keys search.



More information about the Python-list mailing list