>>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. -tkc (who's translating from vim regexps which are just diff. enough to throw a wrench in works...) -- http://mail.python.org/mailman/listinfo/python-list