Match First Sequence in Regular Expression?

Christoph Conrad nospam at spamgourmet.com
Thu Jan 26 09:19:26 EST 2006


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)] + "\""

Best wishes,
 Christoph



More information about the Python-list mailing list