Match First Sequence in Regular Expression?

Roger L. Cauvin roger at
Thu Jan 26 10:20:35 EST 2006

"Christoph Conrad" <nospam at> wrote in message 
news:upsmfjcks.fsf at
> Hello Roger,
>> I'm looking for a regular expression that matches the first, and only
>> the first, sequence of the letter 'a', and only if the length of the
>> sequence is exactly 3.
> import sys, re, os
> if __name__=='__main__':
>    m ='a{3}', 'xyz123aaabbaaabbbbababbbbaabb')
>    print
>    print "Preceded by: \"" + m.string[0:m.start(0)] + "\""

The correct pattern should reject the string:


since the length of the first sequence of the letter 'a' is 2.  Yours 
accepts it, right?

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

More information about the Python-list mailing list