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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 12:10:12  来源:igfitidea点击:

What does the regex \S mean in JavaScript?

javascriptregex

提问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

\smatches whitespace (spaces, tabs and new lines). \Sis negated \s.

\s匹配空白(空格、制表符和新行)。\S被否定\s

回答by Klaus Byskov Pedersen

\Smatches 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 \smetacharactermatches whitespace characters.

\s元字符空格字符匹配。