How can I exclude some characters from a class?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 16:12:34

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/3548949/how-can-i-exclude-some-characters-from-a-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!