\W
detects following non-word characters
\\ 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
Below are two lines, first line starting with #
(is a pure comment), second line is multi-line string with intermittent comments
# 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)
Some of the above lines have \
as the last non-word character.
Goal is to construct the above syntax to a single string: 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)
How to detect backslash \
on end of every line? Because...
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..