如何从课程中排除某些字符?

时间:2010-08-23 15:17:33

标签: regex perl character-class

假设我要匹配“字”字符(\w),但要排除“_”,或匹配空白字符(\s),但要排除“\ t”。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:42)

使用包含\ 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