Find non whitespace characters

hello,

I try to find non white space characters with the \S selector. when i write the \S with plus sign (\S+) the answer is different if i do it without the + sign. it returns only 13 instead of 36 when i use the + sign?

var str = "the man and the dog walked 4 in the avenue 5 d 4";
        
        
       console.log(str.match(/\S+/gi).length);

var str = "the man and the dog walked 4 in the avenue 5 d 4";
       console.log(str.match(/\S+/gi));

(13) ["the", "man", "and", "the", "dog", "walked", "4", "in", "the", "avenue", "5", "d", "4"]

var str = "the man and the dog walked 4 in the avenue 5 d 4";
       console.log(str.match(/\S/gi));

(36) ["t", "h", "e", "m", "a", "n", "a", "n", "d", "t", "h", "e", "d", "o", "g", "w", "a", "l", "k", "e", "d", "4", "i", "n", "t", "h", "e", "a", "v", "e", "n", "u", "e", "5", "d", "4"]

\\s - matches single non- whitespace character
\\s+ - matches sequence of one or more non- whitespace characters.
2 Likes

thanks for the clear answer!