2010-08-23 39 views
22

说我想匹配一个“单词”字符(\w),但排除“_”或匹配一个空格字符(\s),但排除“\ t”。我怎样才能做到这一点?如何排除班级中的某些人物?

+3

对于其他人谁可以使用Java,.NET,XML架构,或JGSoft /使用RegexBuddy的利益,实际上是为那些口味字符减去机构:http://stackoverflow.com/questions/3201689/character-class-subtraction-conversion-from-java-syntax-to-regexbuddy;例如.NET中的[a-z- [aeiou]]匹配小写的辅音。 – polygenelubricants 2010-08-23 18:05:44

回答

36

使用否定类,包括\ W或\ 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 
+4

+1我称这种技术为[双负](http://stackoverflow.com/questions/3469080/match-whitespace-but-not-newlines-perl/3469155#3469155)。 – 2010-08-23 15:54:14