What does the regex \S mean in JavaScript?

JavascriptRegex

Javascript Problem Overview


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);
    }
}

Javascript Solutions


Solution 1 - Javascript

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

Solution 2 - Javascript

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

Solution 3 - Javascript

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

Solution 4 - Javascript

/\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 - Javascript

The \s metacharacter matches whitespace characters.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsteveView Question on Stackoverflow
Solution 1 - JavascriptRichard HView Answer on Stackoverflow
Solution 2 - JavascriptKlaus Byskov PedersenView Answer on Stackoverflow
Solution 3 - JavascriptSpiny NormanView Answer on Stackoverflow
Solution 4 - JavascriptVictor NicolletView Answer on Stackoverflow
Solution 5 - JavascriptnickView Answer on Stackoverflow