I need a regex in Python2 to match only horizontal white spaces not newlines.
\s
matches all whitespaces including newlines.
>>> re.sub(r"\s", "", "line 1.\nline 2\n")
'line1.line2'
\h
does not work at all.
>>> re.sub(r"\h", "", "line 1.\nline 2\n")
'line 1.\nline 2\n'
[\t ]
works but I am not sure if I am missing other possible white space characters especially in Unicode. Such as \u00A0
(non breaking space) or \u200A
(hair space). There are much more white space characters at the following link: https://www.cs.tut.fi/~jkorpela/chars/spaces.html (dead link)
>>> re.sub(r"[\t ]", "", u"line 1.\nline 2\n\u00A0\u200A\n", flags=re.UNICODE)
u'line1.\nline2\n\xa0\u200a\n'
Do you have any suggestions?