Find Whitespace with Regular Expressions [Solved]

I have been at this issue for over two weeks, Having to difficut solving it. I have gone through others answers that people solved for me its not working. this how i solved it
// Setup
var testString = “How many spaces are there in this sentence?”;

// Only change code below this line.
var expression = /\S+/g;
/* ATSlade modified the above line for the solution …why use “i” though? …and what does “invert” mean? */

// Only change code above this line.
// We use this function to show you the value of your variable in your output box.
return(testString.match(expression).length);
})();(function(){return(test);})(); this is wrong what is gthe right code

\S will find NON white space characters
\S+ will find NON white space characters only with characters following them

You want to work with \s which is white space

The only thing you have to do ‘pass this’ is write the write definition of var expression (which is /\s+/g). The i is irrelevant when dealing with white space

Thanks see code below
var test = (function(){
var testString = “How many spaces are there in this sentence?”;

var expression = /\s+/g; /* ATSlade altered this line for the solution */

return(testString.match(expression).length);
})();(function(){return(test);})();
but they want me to find regular expression should find seven spaces in testString. how do i do that

I don’t think this is the original code that they provided - please hit the reset button on the left hand side and paste what it looks like

This is the code I have changed some of it but it’s not working
/ 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;
return(restSring);

what happens if you remove the plus?

I removed the ? nothing has happened i don’t know what to do

Um - so why does the end of your function say return(restString);

Where is restString defined on your page?

see below
/ 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;
return(testSring);

You’ve inserted extra code into your problem - and i think you might have a problem with spaces

This is the original code that i copied from the problem


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

// Only change code below this line.

var expression = /.+/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;

There’s no return - there’s a space between g; and the comment - your code has extra information that shouldn’t be there - there’s no function declaration there should be no ‘return’ statement. on the left third of the page near the bottom is a button that says reset - i suggest you push it and start over

Are you the best thanks. It has taken me two weeks to solve this issue. It worked

DOn’t be afraid to use the reset button - one small change could be impossible to find and throw you off

1 Like