[Tutor] escape character regex
Ian D
duxbuz at hotmail.com
Sat Mar 28 20:37:58 CET 2015
Hi
I run a regex like this:
>pchars = re.compile('\x00\x00\x00') #with or without 'r' for raw
on a string like this:
>data = "['broadcast', 'd8on\x00\x00\x00\x11broadcast', 'd11on']"
>print "found pchars :",pchars.findall(data)
which returns:
>found pchars : ['\x00\x00\x00']
But if I try to match the extra digits at the end like this:
>pchars = re.compile('\x00\x00\x00\x\d+')
I get an error:
>ValueError: invalid \x escape
Or if I use another ide than idle it actually flags it as an "illegal hexadecimal escape sequence"
How could I match the \x00\x00\x00\x11 portion of the string?
I have tried escape sequence \\x
Thanks
More information about the Tutor
mailing list