import re import time import fpformat Regex1 = re.compile("^(a|b|c|d|e|f|g)+$") Regex2 = re.compile("^[a-g]+$") TimesToDo = 1250; TestString = "" for i in range(800): TestString += "abababdedfg" StartTime = time.time() for i in range(TimesToDo): Regex1.search(TestString) Seconds = time.time() - StartTime print "Alternation takes " + fpformat.fix(Seconds,3) + " seconds" StartTime = time.time() for i in range(TimesToDo): Regex2.search(TestString) Seconds = time.time() - StartTime print "Character class takes " + fpformat.fix(Seconds,3) + " seconds" ----------------------------------------------------------------------------- Copyright 1997-2024 Jeffrey Friedl