
July 22, 2009
8:22 a.m.
MRAB wrote:
Extend the current re.match and re.search to accept a tuple of patterns:
m = re.match((pattern0, pattern1, pattern2, pattern3), s) if m: print m.group()
Also give the match object an 'index' attribute indicating which pattern matched, so you can do m = re.match((pattern1, pattern2, pattern3, pattern4), s) if m: if m.index == 0: # pattern0 matched elif m.index == 1: # pattern1 matched # etc. -- Greg