"Tim Chase" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >>>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'.) > > Anchoring it to the beginning/end might solve that: > > r = re.compile("^[^a]*a{3}b+(a+b*)*$") > > this ensures that no "a"s come before the first 3x"a" and nothing but "b" > and "a" follows it.
Anchoring may be the key here, but this pattern rejects "xayz123aaabab" which it should accept, since the 'a' between the 'x' and the 'y' is not directly followed by the letter 'b'. -- Roger L. Cauvin [EMAIL PROTECTED] (omit the "nospam_" part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list