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
Post a Comment