Thursday, January 06, 2011

Madness ...

I'm in idle (python 2.7) and see the following:

>>> p = re.compile(r"^(\d{2}/\d{2}/\d{2})")
>>> p = re.compile(r"^(\d[2}/\d{2}/\d{4})")

Traceback (most recent call last):
File "", line 1, in
p = re.compile(r"^(\d[2}/\d{2}/\d{4})")
File "/usr/lib/python2.7/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.7/re.py", line 245, in _compile
raise error, v # invalid expression
error: unexpected end of regular expression

The first regular expression compiles, the second one does not. The only difference I can see is the "4". What is going on here?

Ooops. Just before I was about to post this, I found the problem. Do you see it? It's not easy to see.