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

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

This question already has an answer here:

Reference – What does this regex mean?

1 answer

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) {


Solution 1:

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

Solution 2:

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

Solution 3:

I believe it means ‘anything but a whitespace character’.

Solution 4:

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

Solution 5:

The \s metacharacter matches whitespace characters.