2018-10-10 18:03:03 -04:00
---
id: 587d7db9367417b2b2512ba4
2021-02-06 04:42:36 +00:00
title: Match Non-Whitespace Characters
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 18210
2021-01-13 03:31:00 +01:00
dashedName: match-non-whitespace-characters
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
You learned about searching for whitespace using `\s` , with a lowercase `s` . You can also search for everything except whitespace.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
Search for non-whitespace using `\S` , which is an uppercase `s` . 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 `[^ \r\t\f\n\v]` .
2020-08-04 15:14:01 +08:00
```js
let whiteSpace = "Whitespace. Whitespace everywhere!"
let nonSpaceRegex = /\S/g;
whiteSpace.match(nonSpaceRegex).length; // Returns 32
```
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 `countNonWhiteSpace` to look for multiple non-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(countNonWhiteSpace.global);
```
2021-02-06 04:42:36 +00:00
Your regex should use the shorthand character `\S` to match all non-whitespace characters.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(/\\S/.test(countNonWhiteSpace.source));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should find 35 non-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(countNonWhiteSpace)
.length == 35
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find 23 non-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(countNonWhiteSpace).length == 23);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find 21 non-spaces in `"MindYourPersonalSpace"`
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert('MindYourPersonalSpace'.match(countNonWhiteSpace).length == 21);
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 countNonWhiteSpace = /change/; // Change this line
let result = sample.match(countNonWhiteSpace);
```
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 countNonWhiteSpace = /\S/g; // Change this line
let result = sample.match(countNonWhiteSpace);
```