2018-10-10 18:03:03 -04:00
---
id: 587d7db8367417b2b2512ba3
2021-02-06 04:42:36 +00:00
title: Match Whitespace
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 301359
2021-01-13 03:31:00 +01:00
dashedName: match-whitespace
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
The challenges so far have covered matching letters of the alphabet and numbers. You can also match the whitespace or spaces between letters.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
You can search for whitespace using `\s` , which is a lowercase `s` . This pattern not only matches whitespace, but also carriage return, tab, form feed, and new line characters. You can think of it as similar to the character class `[ \r\t\f\n\v]` .
2020-08-04 15:14:01 +08:00
```js
let whiteSpace = "Whitespace. Whitespace everywhere!"
let spaceRegex = /\s/g;
whiteSpace.match(spaceRegex);
// Returns [" ", " "]
```
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Change the regex `countWhiteSpace` to look for multiple whitespace characters in a string.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should use the global flag.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(countWhiteSpace.global);
```
2021-02-06 04:42:36 +00:00
Your regex should use the shorthand character `\s` to match all whitespace characters.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(/\\s/.test(countWhiteSpace.source));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should find eight spaces in `"Men are from Mars and women are from Venus."`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(
'Men are from Mars and women are from Venus.'.match(countWhiteSpace).length ==
8
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find three spaces in `"Space: the final frontier."`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert('Space: the final frontier.'.match(countWhiteSpace).length == 3);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find no spaces in `"MindYourPersonalSpace"`
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert('MindYourPersonalSpace'.match(countWhiteSpace) == null);
2018-10-10 18:03:03 -04:00
```
2020-08-04 15:14:01 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
let sample = "Whitespace is important in separating words";
let countWhiteSpace = /change/; // Change this line
let result = sample.match(countWhiteSpace);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let sample = "Whitespace is important in separating words";
let countWhiteSpace = /\s/g;
let result = sample.match(countWhiteSpace);
```