JavaScript 中的正则表达式 \S 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4377480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the regex \S mean in JavaScript?
提问by steve
What does /\S/ mean in a regex?
/\S/ 在正则表达式中是什么意思?
while (cur ! = null) {
if (cur.nodeType == 3 && ! /\S/. test(cur.nodeValue)) {
element. removeChild(cur);
} else if (cur. nodeType == 1) {
cleanWhitespace(cur);
}
}
回答by Richard H
\s
matches whitespace (spaces, tabs and new lines). \S
is negated \s
.
\s
匹配空白(空格、制表符和新行)。\S
被否定\s
。
回答by Klaus Byskov Pedersen
\S
matches anything but a whitespace, according to this reference.
\S
根据此参考,匹配除空格以外的任何内容。
回答by Spiny Norman
I believe it means 'anything but a whitespace character'.
我相信这意味着“除了空白字符之外的任何东西”。
回答by Victor Nicollet
/\S/.test(string)
returns true if and only if there's a non-space character in string
. Tab and newline count as spaces.
/\S/.test(string)
当且仅当string
. 制表符和换行符算作空格。
回答by nick
The \s
metacharactermatches whitespace characters.
该\s
元字符空格字符匹配。