Match Whitespace

Tell us what’s happening:

Your code so far

let sample = "Whitespace is important in separating words";
let countWhiteSpace = /change/; // Change this line
let result = sample.match(countWhiteSpace);

Your browser information:

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

Link to the challenge:

so this lesson is about getting comfortable withRegex (or regular expressions) in javascript, and regex in general. It’s a challenging concept, and one many programmers will skirt around by finding other ways to solve the same problem.

Neat thing about regex, though, is that it allows for much more concise solutions to problems, where a text or numeric or whitespace comparator might become far more verbose.

FCC gives a pretty solid introduction to regular expressions, but it is a subject that is much more massive than a few lessons here can cover. Thus, as they tell you in almost every lesson, Research, Read, Ask.

  • Find other resources that talk about regular expressions, and what they can do.
  • Look up “regex recipes” for example, where people talk about common problems regex can help solve.
  • Find a site that will let you test out regular expressions against actual strings – personally, I tend to use RegexTester quite a lot. I like that it will comment on my regex, and allow me to save them for others to view/comment.

So this lesson asks you to use the regex that matches “any whitespace character”. That would be spaces (en or em spaces), tabs, any character that’s not a letter, number or symbol.

Take a look in the first paragraph of this response, there’s a link to the Mozilla Developer site or MDN, with a very comprehensive page about regular expression. The answer you seek is there.

1 Like