How to match tab and new line, but not space with REGEX?

I am trying to match meta characters "tab" and "newline", but without "spaces" with REGEX in Java.

\ s matches evrything, i.e. tab, space and new line ... But I do not want the "space" to match.

How to do it?

Thanks.

+6
source share
2 answers

One way to do this:

[^\\S ] 

The character class being denied makes this regular expression match anything except - \\S (non-whitespace) and " " (space). Thus, it will match \\S , except for a space.

+19
source

We explicitly list them inside [...] (character set):

 "[\\t\\n\\r\\f\\v]" 
+2
source

All Articles