Invert Regular Expression Matches with JavaScript

Tell us what’s happening:

Your code so far

// Setup
var testString = "How many non-space characters 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 nonSpaceCount = testString.match(expression).length;

Your browser information:

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

Link to the challenge:

You used /\s/g , so your code will match all whitespace characters.

Take a look at the information in the top-right corner:

For example, \s will match any whitespace, and \S will match anything that isn’t whitespace.

Now take a closer look at the instructions:

Use /\S/g to count the number of non-whitespace characters in testString

So you have to use /\S/g to match all non-whitespace characters.