2010/9/25 AON LAZIO <aonla...@gmail.com>: > Hi, > Say I have > p = re.compile('a|b') > text = 'a' > d = p.findall(text) > #d -> ['a'] > What is the way to find out which pattern p match (the former or latter)? > I mean without knowing the outcome of p.findall > Thanks > > -- > Aonlazio > 'Peace is always the way.' NW > > -- > http://mail.python.org/mailman/listinfo/python-list > >
Hi, I am not sure, I understand the task completely, but maybe named subpatterns and the groupdict data for the match objects may help? for m in re.finditer(r"(?P<patternA>A)|(?P<patternB>B)", "QABCZ"): print m.group(), m.groupdict() A {'patternB': None, 'patternA': 'A'} B {'patternB': 'B', 'patternA': None} regards, vbr -- http://mail.python.org/mailman/listinfo/python-list