* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
78 lines
1.8 KiB
Markdown
78 lines
1.8 KiB
Markdown
---
|
|
id: 587d7db8367417b2b2512ba3
|
|
title: Match Whitespace
|
|
challengeType: 1
|
|
forumTopicId: 301359
|
|
dashedName: match-whitespace
|
|
---
|
|
|
|
# --description--
|
|
|
|
The challenges so far have covered matching letters of the alphabet and numbers. You can also match the whitespace or spaces between letters.
|
|
|
|
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]`.
|
|
|
|
```js
|
|
let whiteSpace = "Whitespace. Whitespace everywhere!"
|
|
let spaceRegex = /\s/g;
|
|
whiteSpace.match(spaceRegex);
|
|
// Returns [" ", " "]
|
|
```
|
|
|
|
# --instructions--
|
|
|
|
Change the regex `countWhiteSpace` to look for multiple whitespace characters in a string.
|
|
|
|
# --hints--
|
|
|
|
Your regex should use the global flag.
|
|
|
|
```js
|
|
assert(countWhiteSpace.global);
|
|
```
|
|
|
|
Your regex should use the shorthand character `\s` to match all whitespace characters.
|
|
|
|
```js
|
|
assert(/\\s/.test(countWhiteSpace.source));
|
|
```
|
|
|
|
Your regex should find eight spaces in `"Men are from Mars and women are from Venus."`
|
|
|
|
```js
|
|
assert(
|
|
'Men are from Mars and women are from Venus.'.match(countWhiteSpace).length ==
|
|
8
|
|
);
|
|
```
|
|
|
|
Your regex should find three spaces in `"Space: the final frontier."`
|
|
|
|
```js
|
|
assert('Space: the final frontier.'.match(countWhiteSpace).length == 3);
|
|
```
|
|
|
|
Your regex should find no spaces in `"MindYourPersonalSpace"`
|
|
|
|
```js
|
|
assert('MindYourPersonalSpace'.match(countWhiteSpace) == null);
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
let sample = "Whitespace is important in separating words";
|
|
let countWhiteSpace = /change/; // Change this line
|
|
let result = sample.match(countWhiteSpace);
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
let sample = "Whitespace is important in separating words";
|
|
let countWhiteSpace = /\s/g;
|
|
let result = sample.match(countWhiteSpace);
|
|
```
|