Match First Sequence in Regular Expression?
python.list at tim.thechases.com
Thu Jan 26 18:47:06 CET 2006
The below seems to pass all the tests you threw at it (taking the
modified 2nd test into consideration)
One other test that occurs to me would be
where you have "aaab" in there twice.
tests = [
exp = '^([^b]|((?<!a)b))*aaab+[ab]*$'
r = re.compile(exp)
print "Using regexp: %s" % exp
for test,expectedResult in tests:
result = True
result = False
if result == expectedResult:
print "%s passed" % test
print "%s failed (expected %s, got %s)" % (
More information about the Python-list