[Python-Dev] New regex module for 3.2?

Georg Brandl g.brandl at gmx.net
Fri Jul 9 08:54:31 CEST 2010


Am 09.07.2010 02:35, schrieb MRAB:

>> That's not what I'm asking. I'm asking what happens if you take an
>> existing Python installation's re module, move it aside, and drop
>> regex in its place as "re.py".
>> 
>> Doing that and then running Python's own test suite as well as the
>> test suites of major Python applications and frameworks like Twisted,
>> Zope and Django would provide solid evidence that the new version
>> really *is* backwards compatible, rather than that it is *meant* to be
>> backwards compatible.
>> 
> I had to recompile the .pyd to change its internal name from "regex" to
> "re", but apart from that it passed Python's own test suite except for
> where I expected it to fail:
> 
> 1. Some of the inline flags are scoped; for example, putting "(?i)" at
> the end of a regex will now have no effect because it's no longer a
> global, all-or-nothing, flag.

That is problematic.  I've often seen people put these flags at the end
of a regex, probably for readability purposes.  IMHO it would be better
to limit flag scoping to the explicit (?flags-flags: ) groups.

> 2. The .sub method will treat unmatched groups in an expansion as empty
> strings. The re module raises an exception in such cases, which means
> that users currently need a workaround.

That is a change for the better, I would say.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-Dev mailing list