Find Whitespace with Regular Expressions, problem in console

Find Whitespace with Regular Expressions, problem in console
0.0 0

#1

Hi Everyone,
I think there is some problem in dummy console, because for this test when I am putting more space in between words and running the code, still its showing output as 7.

Your code so far

// Setup
var testString = "How many spaces are there     in this sentence?";

// Only change code below this line.

var expression = /\s+/g;  // Change this line

// Only change code above this line

// This code counts the matches of expression in testString
var spaceCount = testString.match(expression).length;

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36.

Link to the challenge:


#2

The dummy console is showing the correct value. The regular expression /\s+/g matches instances of on or more white spaces characters appear. There are only 7 in the testString sentence. The + is the 1 or more part. If you put 5 spaces in a row it only gets counted as one match. If you remove the + and just have \s, then it will count each white space character.