Regular expressions use the backslash character ('\') to indicate
special forms or to allow special characters to be used without
invoking their special meaning. ...
The solution is to use Python’s raw string notation for regular
expression patterns; backslashes are not handled in any special way in
a string literal prefixed with 'r'. So r"\n" is a two-character string
containing '\' and 'n', while "\n" is a one-character string
containing a newline. Usually patterns will be expressed in Python
code using this raw string notation.
使用原始字符串:
或者避开反斜杠:
试试看
为什么不起作用?你可以理解
见What does preceding a string literal with "r" mean?
使用原始字符串:
原始字符串文字,即前缀为
'r'
的字符串文字,使反斜杠被视为文字。反斜杠被视为转义序列。你知道吗引用^{} — Regular expression operations :
相关问题 更多 >
编程相关推荐