regex - Python: Why do raw strings require backslash to be escaped? -


this question has answer here:

this explanation python documentation:

both string , bytes literals may optionally prefixed letter 'r' or 'r'; such strings called raw strings , treat backslashes literal characters. result, in string literals, '\u' , '\u' escapes in raw strings not treated specially. given python 2.x’s raw unicode literals behave differently python 3.x’s 'ur' syntax not supported.

if raw strings treat backslashes char literals, why backslash need escaped in expression:

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

instead of being able write:

re.compile(r"'\'") 

to capture single backslash when using re module?

because '\' has special meaning in re means escape character after in language use define re if want match '+' character re '\+'


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 -