Python Forum

Full Version: Deny backslash using regex
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My backslash don't work ?
SyntaxError: EOL while scanning string literal

Exemple backslash :

v_char = "search?q=\"

o_rex = re.match(r"^(?!.*\).*$", v_char, re.IGNORECASE)

try:
    v_res = o_rex.string
    print("Security data . . .")

except(TypeError, AttributeError):
    print("Insecure data !")
You have probably typed or copied that string yourself.
When it parsed or coming other placed from python it will be \\:
v_char = "search?q=\\"
This is because of escape character,so python read it as one \.
Will see this if use print().
>>> v_char = "search?q=\\"
>>> v_char 
'search?q=\\'
>>>
>>> print(v_char)
>>> search?q=\