I am very new to regex and trying to get the "\" character using python
I can usually escape "\" like this
print ("\\"); print ("i am \\nit");
conclusion
\ i am \nit
but when i use the same in regX it doesn't work as i thought
print (re.findall(r'\\',"i am \\nit"));
and give me the conclusion
['\\']
can someone explain why
EDIT. , print . , , , , - '\\'. , findall , print , . :
print
'\\'
findall
>>> print(re.findall(r'\\',"i am \\nit")[0]) \
( , ( ), , , , , .)
r , "" , \ ( " " ).
r
\
r'\' , ,
r'\'
, ; , r "\" " , : ; r "\" ( ). , ( ).
: "\\".
"\\"
- ,
re.findall , . , , , .
re.findall
['\\'], '\\' - , " " - , , print "\\".
print "\\"
, - "a string" r"a raw string". , , , . , , , ( , escape-), , , , , , .
"a string"
r"a raw string"
There is no need to avoid backslashes in raw strings unless the backslash precedes the final quote.