escaping \n in \s match in reg ex python
问题 I want to substitute all space characters (except \n ) with "" . I tried using regular expression with \s+ but it matches with newline character as well. Is there any method to skip \n in \s in regex? 回答1: If you do not have to think of Unicode, you could use [ \t\r\f\v] Or, since \v matches a VT (verical symbol, \x0b ), \r is also considered a line break, and \f is also a kind of a vertical whitespace (rather obsolete now though - (form feed, \x0c ): [ \t] See docs: \s When the UNICODE flag