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

What does /\S/ mean in a regex?

while (cur ! = null) {
    if (cur.nodeType == 3 && ! /\S/. test(cur.nodeValue)) {
        element. removeChild(cur);
    } else if (cur. nodeType == 1) {
        cleanWhitespace(cur);
    }
}

This question is related to javascript regex

The answer is


The \s metacharacter matches whitespace characters.


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


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


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


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