开发者

What does the regex \S mean in JavaScript? [duplicate]

开发者 https://www.devze.com 2023-01-29 20:48 出处:网络
This question already has an answer here: Reference - What does this regex mean? (1 answer) Closed 4 years ago.
This question already has an answer here: Reference - What does this regex mean? (1 answer) Closed 4 years ago.

What does /\S/ mean in a regex?

while (cur ! = null) {
    if (cur.nodeType == 3 && ! /\S/. test(cur.nodeValue)) {
        element. removeC开发者_如何学Child(cur);
    } else if (cur. nodeType == 1) {
        cleanWhitespace(cur);
    }
}


\s matches whitespace (spaces, tabs and new lines). \S is negated \s.


\S matches anything but a whitespace, according to this reference.


I believe it means 'anything but a whitespace character'.


/\S/.test(string) returns true if and only if there's a non-space character in string. Tab and newline count as spaces.


The \s metacharacter matches whitespace characters.

0

精彩评论

暂无评论...
验证码 换一张
取 消