I was browsing through the source code of Django when I found the following regular expression:

tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')

As it turns out, this line from the message module in the Python standard library's email module. It seems to be used to determine if an email header parameter's value contains special characters to determine whether it should be wrapped in quotes.

What strikes me as odd about this regex is that the parentheses and the question-mark are escaped with backslashes. I know that's necessary for including those literals in the rest of the expression, but they shouldn't need to be escaped within a character class, right? Shouldn't this be functionally equivalent to the much more readable:

tspecials = re.compile(r'[ ()<>@,;:\\"/\[\]?=]')
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to