How can I exclude some characters from a class?

23.8k Views Asked by At

Say I want to match a "word" character (\w), but exclude "_", or match a whitespace character (\s), but exclude "\t". How can I do this?

1

There are 1 best solutions below

4
On BEST ANSWER

Use a negated class including \W or \S.

/[^\W_]/  # anything that's not a non-word character and not _
/[^\S\t]/ # anything that's not a non-space character and not \t