reusing parts of a string in RE matches?

John Salerno johnjsal at NOSPAMgmail.com
Thu May 11 10:17:25 EDT 2006


Ben Cartwright wrote:

> Yes, and no extra for loops are needed!  You can define groups inside
> the lookahead assertion:
> 
>   >>> import re
>   >>> re.findall(r'(?=(aba))', 'abababababababab')
>   ['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']

Wow, that was like magic! :)



More information about the Python-list mailing list