[Python-ideas] Experiment: Adding "re" to string objects.

Jan Kaliszewski zuo at chopin.edu.pl
Sun Jul 19 20:45:32 CEST 2009


Antoine Pitrou <solipsis at pitrou.net> wrote:

> Georg Brandl <g.brandl at ...> writes:
>>
>> 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)
>
> -0.5. Right now, objects in the re module are constructed from a regular
> expression pattern -- one of the reasons being that these patterns are  
> compiled
> to bytecode form, and the objects help retain the bytecode. Having  
> another
> object type constructed from the string-to-match is confusing.

Maybe it should be limited to using compiled regexps, not strings?

> Besides, keeping
> some kind of internal state about the last matched pattern, only for
> "convenience" purposes, isn't pretty either.

But 'practicality beats purity' :)

-- 
Jan Kaliszewski <zuo at chopin.edu.pl>



More information about the Python-ideas mailing list