Find non whitespace characters

Find non whitespace characters
0

#1

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


#2
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.

#3

thanks for the clear answer!