reusing parts of a string in RE matches?

John Salerno johnjsal at
Wed May 10 21:25:24 CEST 2006

mpeters42 at wrote:

>>>> string = 'abababababababab'
>>>> pat = 'aba'
>>>> [pat for s in re.compile('(?='+pat+')').findall(string)]
> ['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']

Wow, I have no idea how to read that RE. First off, what does it match? 
Should something come before the parentheses, and that will be what 
matches? Also, what are the '+'s doing? Are they literal +s or still 
being used as RE syntax?

More information about the Python-list mailing list