tags:

views:

101

answers:

4

I tried this but it doesn't work :

[^\s-]

Any Ideas?

A: 

Perhaps the - is being confused for a range operator (as in [a-z]). Try putting it first.

[^-\s]
Marcelo Cantos
+2  A: 
[^\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.
codaddict
+3  A: 

Which programming language are you using? May be you just need to escape the backslash like "[^\\s-]"

Cagdas
\s stands for whitespaceif you backslash the backslash it has an completly different meaning
rudimenter
@rudimenter: Cagdas was just suggesting that there might be different behavior depending on your environment (which you didn't tell us).
0xA3
@rudimenter: If the regex is defined by a string, then you need to escape the backslash or use a verbatim string like `@"string"` in .NET or `r"string"` in Python.
Tim Pietzcker
+2  A: 
polygenelubricants
very strangeit works now with my original patterndon't know what was wrong before
rudimenter