What is the Regular Expression For “Not Whitespace and Not a hyphen”

[^\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.

Leave a Comment