Find Whitespace with Regular Expressions [Solved]

Find Whitespace with Regular Expressions [Solved]
0

#1

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


#2

\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


#3

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


#4

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


#5

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


#6

what happens if you remove the plus?


#7

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


#8

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

Where is restString defined on your page?


#9

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


#10

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


#11

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


#12

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