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?
views:
74answers:
1
+11
A:
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
ysth
2010-08-23 15:21:10
+1 I call this technique a [double-negative](http://stackoverflow.com/questions/3469080/match-whitespace-but-not-newlines-perl/3469155#3469155).
Greg Bacon
2010-08-23 15:54:14