How to write a regex
with matches whitespace but no tabs and new line?
I tried [[:blank:]]{2,}
; however, this doesn't work for me because its whitespace or tab but not newlines.
As per my original comment, you can use this.
Note: The link contains whitespace characters: tab, newline, and space. Only space is matched.
[^\S\t\n\r]
So your regex would be [^\S\t\n\r]{2,}
[^\S\t\n\r]
Match any character not present in the set.
\S
Matches any non-whitespace character. Since it's a double negative it will actually match any whitespace character. Adding \t
, \n
, and \r
to the negated set ensures we exclude those specific characters as well. Basically, this regex is saying:
\t\n\r
This principle in regex is often used with word characters \w
to negate the underscore _
character: [^\W_]