13

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

\s matches evrything i.e. tab, space and new line... But, I don't want "space" to be matched.

How do I do that?

Thanks.

Akshay Lokur
  • 6,680
  • 13
  • 43
  • 62

2 Answers2

24

One way to do it is:

[^\\S ]

The negated character class makes this regex to match anything except - \\S (non-whitespace) and " "(space) character. So, it will match \\s except space.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
9

Explicitly list them inside [...] (set of characters):

"[\\t\\n\\r\\f\\v]"
falsetru
  • 357,413
  • 63
  • 732
  • 636