How can I exclude some characters from a class?

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?

Answers


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

Need Your Help

Prevent DialogFragment from dismissing when button is clicked

android dialog onclick android-dialogfragment

I have a DialogFragment with a custom view which contains two text fields where the user is to input their username and password. When the positive button is clicked, I want to validate that the user

What is the fastest way to clone a git repository over a fast network connection?

git performance vmware git-clone

I have a situation with a relatively large git repository located on an elderly, slow host on my local network where it takes quite a while to do the initial clone.