Regex makeover: spiffification

By Filip Salomonsson; published on September 18, 2006.

Python's regex objects could be spiffier. Rough goal:

>>> foo = re.compile(r"a*b")
>>> bar = re.compile(r"c|d+")
>>> baz = foo + bar
>>> type(baz)
<_sre.SRE_Pattern object at 0xb7ee9500>
>>> baz.pattern
'a*b(?:c|d+)'
>>> boink = foo | bar
>>> type(boink)
<_sre.SRE_Pattern object at 0xb7efe240>
>>> boink.pattern
'(?:a*b)|(?:c|d+)'

(There are more things on my wishlist, but let's start small.)

Next up: baby steps.