Match First Sequence in Regular Expression?
Roger L. Cauvin
roger at deadspam.com
Thu Jan 26 11:23:05 EST 2006
"Tim Chase" <python.list at tim.thechases.com> wrote in message
news:mailman.1082.1138290258.27775.python-list at python.org...
>> Sorry for the confusion. The correct pattern should reject
>> all strings except those in which the first sequence of the
>> letter 'a' that is followed by the letter 'b' has a length of
>> exactly three.
>
> Ah...a little more clear.
>
> r = re.compile("[^a]*a{3}b+(a+b*)*")
> matches = [s for s in listOfStringsToTest if r.match(s)]
Wow, I like it, but it allows some strings it shouldn't. For example:
"xyz123aabbaaab"
(It skips over the two-letter sequence of 'a' and matches 'bbaaab'.)
--
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