Match First Sequence in Regular Expression?

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


"Christoph Conrad" <nospam at spamgourmet.com> wrote in message 
news:upsmfjcks.fsf at ID-24456.user.uni-berlin.de...
> 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 = re.search('a{3}', 'xyz123aaabbaaabbbbababbbbaabb')
>    print m.group(0)
>    print "Preceded by: \"" + m.string[0:m.start(0)] + "\""

The correct pattern should reject the string:

'xyz123aabbaaab'

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

-- 
Roger L. Cauvin
nospam_roger at cauvin.org (omit the "nospam_" part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com





More information about the Python-list mailing list