[Tutor] Regular Expressions: escaping in character classes/character sets

Kent Johnson kent37 at tds.net
Mon Jul 7 12:28:56 CEST 2008


On Mon, Jul 7, 2008 at 1:44 AM, Josh Rosen <rosenville at gmail.com> wrote:
> I was browsing through the source code of Django when I found the following
> regular expression:
>
> tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')
>
> Shouldn't this be
> functionally equivalent to the much more readable:
>
> tspecials = re.compile(r'[ ()<>@,;:\\"/\[\]?=]')

Yes, I think so. Try it and see!

Kent


More information about the Tutor mailing list