如何从班级中排除某些字符? [英] How can I exclude some characters from a class?
本文介绍了如何从班级中排除某些字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我想匹配一个单词"字符(\w
),但排除"_",或者匹配一个空白字符(\s
),但排除"\ t".我怎样才能做到这一点?
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?
推荐答案
使用否定的类,包括\ W或\ S.
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
这篇关于如何从班级中排除某些字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文