Python: Capturing double backslash C char with regex -


i'm attempting capture '\\' python regex via re module. have attempted using:

back = re.compile(r"'\\'") print back.findall(line) 

where line is: char = '\\';

but doesn't capture anything.

i tried:

 = re.compile("'\\\\'")  print back.findall(line) 

to no avail. what's wrong regex?

you need escape backslash:

back = re.compile(r"'\\\\'") 

code:

>>> = re.compile(r"'\\\\'") >>> line = r"char = '\\';" >>> print back.findall(line) ["'\\\\'"] 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -