Match First Sequence in Regular Expression?

Roger L. Cauvin roger at
Thu Jan 26 14:05:04 EST 2006

"Tim Chase" <python.list at> wrote in message 
news:mailman.1093.1138297753.27775.python-list at
> The below seems to pass all the tests you threw at it (taking the modified 
> 2nd test into consideration)
> One other test that occurs to me would be
> "xyz123aaabbaaabab"
> where you have "aaab" in there twice.

Good suggestion.

> ^([^b]|((?<!a)b))*aaab+[ab]*$

Looks good, although I've been unable to find a good explanation of the 
"negative lookbehind" construct "(?<".  How does it work?

Roger L. Cauvin
nospam_roger at (omit the "nospam_" part)
Cauvin, Inc.
Product Management / Market Research

More information about the Python-list mailing list