[Python-ideas] Proposed convenience functions for re module
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed Jul 22 09:14:16 CEST 2009
En Wed, 22 Jul 2009 03:17:46 -0300, Greg Ewing
<greg.ewing-F+z8Qja7x9Xokq/tPzqvJg at public.gmane.org> escribió:
> Steven D'Aprano wrote:
>
>> def multimatch(s, *patterns):
>> """Do a re.match on s using each pattern in patterns, returning
>> the first one to succeed, or None if they all fail."""
>> for pattern in patterns:
>> m = re.match(pattern, s)
>> if m: return m
>
> How are you supposed to tell which one matched?
m.re contains the matching expression
--
Gabriel Genellina
More information about the Python-ideas
mailing list