What is the Regular Expression For "Not Whitespace and Not a hyphen"

I tried this but it doesn't work :

[^\s-]

Any Ideas?


Solution 1:

[^\s-]

should work and so will

[^-\s]
  • [] : The char class
  • ^ : Inside the char class ^ is the negator when it appears in the beginning.
  • \s : short for a white space
  • - : a literal hyphen. A hyphen is a meta char inside a char class but not when it appears in the beginning or at the end.

Solution 2:

It can be done much easier:

\S which equals [^ \t\r\n\v\f]