Newbie needs regex help

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Mon Dec 6 10:34:56 EST 2010


Dan M <dan at catfolks.net> writes:

> I took at look at http://docs.python.org/howto/regex.html, especially the 
> section titled "The Backslash Plague". I started out trying :

>>>> import re
>>>> r = re.compile('\\\\x([0-9a-fA-F]{2})')
>>>> a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 

The backslash trickery applies to string literals also, not only regexps.

Your string does not have the value you think it has. Double each
backslash (or make your string raw) and you'll get what you expect.

-- Alain.



More information about the Python-list mailing list