\W
检测下列非单词字符
\\ Backslash (\)
\' Single quote (')
\" Double quote (")
\a ASCII Bell (BEL)
\b ASCII Backspace (BS)
\f ASCII Formfeed (FF)
\n ASCII Linefeed (LF)
\r ASCII Carriage Return (CR)
\t ASCII Horizontal Tab (TAB)
\v ASCII Vertical Tab (VT)
\ooo Character with octal value ooo
\xhh Character with hex value hh
\newline Backslash and newline ignored
下面是两行,第一行以
#
(是纯注释),第二行是带有间歇注释的多行字符串
# abc # def
1.3.6.1.4.1.555.2.12.6.102 0x04444001 1.3.6.1.4.1.75.2.12.90.901(1,0)\
# xyz
1.3.6.1.4.1.75.2.12.90.902(2,0)\
# ddd
1.3.6.1.4.1.75.2.12.90.903(3,0)
上面的几行有
\
作为最后一个非单词字符。
目标是将上述语法构造为单个字符串:
1.3.6.1.4.1.555.2.12.6.102 0x04444001 1.3.6.1.4.1.75.2.12.90.901(1,0) 1.3.6.1.4.1.75.2.12.90.902(2,0) 1.3.6.1.4.1.75.2.12.90.903(3,0)
如何检测反斜杠
\
在每一行的末尾?因为…
print(re.search(r'\\', 'hello\there')) # '\\' in r'hello\there' gives None - Because backslash is interpreted as part of Esc seq
print(re.search(r'\\', r'hello\there')) # '\\' in r'hello\there' gives (5,6) - Because raw string interprets backslash as backslash
print(re.search(r'\\$', 'hellothere\')) # \' & \" is also an escape sequence. So, python could not find end of string literal
print(re.search(r'\\', r'hellothere\')) # python should consider backslash as backslash, but, python could not find end of string literal. No clue..