Roger L. Cauvin wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Roger L. Cauvin wrote: >> >>>> $ python test.py >>>> got expected >>>> --------------- >>>> accept accept >>>> reject reject >>>> accept accept >>>> reject reject >>>> accept accept >>> Thanks, but the second test case I listed contained a typo. It should >>> have >>> contained a sequence of three of the letter 'a'. The test cases should >>> be: >>> >>> "xyz123aaabbab" accept >>> "xyz123aabbaaab" reject >>> "xayz123aaabab" accept >>> "xaaayz123abab" reject >>> "xaaayz123aaabab" accept >>> This passes your tests. I haven't closely followed the thread for other requirements:
>>> pattern = ".*?(?<![a+b])aaab" #look for aaab not preceded by any a+b >>> test(pattern) got expected ------ -------- accept accept reject reject accept accept reject reject accept accept >>> >>> testsuite = ( ... ("xyz123aaabbab", "accept"), ... ("xyz123aabbaaab", "reject"), ... ("xayz123aaabab", "accept"), ... ("xaaayz123abab", "reject"), ... ("xaaayz123aaabab", "accept"), ... ) >>> >>> def test(pattern): ... print "got expected" ... print "------ --------" ... for string, result in testsuite: ... m = re.match(pattern, string) ... if m: ... print "accept", ... else: ... print "reject", ... print result ... >>> Michael -- http://mail.python.org/mailman/listinfo/python-list