我使用这个表达式:/\W+/g
来匹配所有不是数字,字母和空格的字符。它似乎包括空间。我如何构建一个不包含空格的正则表达式?
答案 0 :(得分:1)
/[^a-z0-9\s]+/ig
说明:
[^ Character class which matches characters NOT in the following class
a-z All lowercase letters of the alphabet
0-9 All numbers
\s Whitespace characters
] End of the character class
i Case-insensitivity to match uppercase letters
答案 1 :(得分:1)
\W
更准确的措辞是任何非字母数字字符。
\s
适用于任意空白。
所以,它会是这样的: [^ \ s]
答案 2 :(得分:0)
\W
表示“非单词字符”,即\w
的倒数,因此它也会匹配空格。不过,我有点惊讶它不符合数字。