[Python-ideas] Experiment: Adding "re" to string objects.
MRAB
python at mrabarnett.plus.com
Sun Jul 19 16:16:15 CEST 2009
Georg Brandl wrote:
> Nick Coghlan schrieb:
>
>> However, the idea of adding more convenience classes to the re module
>> may still have some merit. In particular, when checking against multiple
>> regexes, being able to do something like the following might be helpful:
>>
>> m = re.Matcher(s)
>> if m.match(r'whatever(.*)'):
>> print m.group(1)
>> elif m.match(r'something (.*) else(.*)'):
>> print m.group(2)
>
> That one looks very useful, and will prevent more proposals of new syntax
> along the lines of "if rex.match(...) as m" :)
>
Or re.match could accept a tuple of patterns and the MatchObject could
have an 'index' property to say which one matched.
More information about the Python-ideas
mailing list