I tried this but it doesn\'t work :
[^\\s-]
Any Ideas?
It can be done much easier:
\S which equals [^ \t\r\n\v\f]
Try [^- ], \s will match 5 other characters beside the space (like tab, newline, formfeed, carriage return).
[^\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.Which programming language are you using? May be you just need to escape the backslash like "[^\\s-]"
In Java:
String regex = "[^-\\s]";
System.out.println("-".matches(regex)); // prints "false"
System.out.println(" ".matches(regex)); // prints "false"
System.out.println("+".matches(regex)); // prints "true"
The regex [^-\s] works as expected. [^\s-] also works.
The hyphen can be included right after the opening bracket, or right before the closing bracket, or right after the negating caret.