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

Antoine Pitrou solipsis at pitrou.net
Sun Jul 19 12:40:07 CEST 2009


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. Besides, keeping
some kind of internal state about the last matched pattern, only for
"convenience" purposes, isn't pretty either.





More information about the Python-ideas mailing list