2018-09-30 23:01:58 +01:00
---
id: 587d7db9367417b2b2512ba4
title: Match Non-Whitespace Characters
challengeType: 1
---
## Description
< section id = 'description' >
You learned about searching for whitespace using < code > \s</ code > , with a lowercase < code > s</ code > . You can also search for everything except whitespace.
Search for non-whitespace using < code > \S</ code > , which is an uppercase < code > s</ code > . This pattern will not match whitespace, carriage return, tab, form feed, and new line characters. You can think of it being similar to the character class < code > [^ \r\t\f\n\v]</ code > .
2019-05-17 06:20:30 -07:00
```js
let whiteSpace = "Whitespace. Whitespace everywhere!"
let nonSpaceRegex = /\S/g;
whiteSpace.match(nonSpaceRegex).length; // Returns 32
```
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
Change the regex < code > countNonWhiteSpace< / code > to look for multiple non-whitespace characters in a string.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: Your regex should use the global flag.
2019-07-24 02:32:04 -07:00
testString: assert(countNonWhiteSpace.global);
- text: Your regex should use the shorthand character < code > \S/code> to match all non-whitespace characters.
testString: assert(/\\S/.test(countNonWhiteSpace.source));
2018-10-04 14:37:37 +01:00
- text: Your regex should find 35 non-spaces in < code > "Men are from Mars and women are from Venus."</ code >
2019-07-24 02:32:04 -07:00
testString: assert("Men are from Mars and women are from Venus.".match(countNonWhiteSpace).length == 35);
2018-10-04 14:37:37 +01:00
- text: 'Your regex should find 23 non-spaces in < code > "Space: the final frontier."</ code > '
2019-07-27 21:16:04 -07:00
testString: 'assert("Space: the final frontier.".match(countNonWhiteSpace).length == 23);'
2018-10-04 14:37:37 +01:00
- text: Your regex should find 21 non-spaces in < code > "MindYourPersonalSpace"</ code >
2019-07-24 02:32:04 -07:00
testString: assert("MindYourPersonalSpace".match(countNonWhiteSpace).length == 21);
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /change/; // Change this line
let result = sample.match(countNonWhiteSpace);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-05-03 03:05:26 -07:00
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /\S/g; // Change this line
let result = sample.match(countNonWhiteSpace);
2018-09-30 23:01:58 +01:00
```
2019-07-18 08:24:12 -07:00
2018-09-30 23:01:58 +01:00
< / section >