2018-10-04 14:47:55 +01:00
|
|
|
---
|
|
|
|
title: Match Whitespace
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Match Whitespace
|
2018-10-04 14:47:55 +01:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-12-21 02:14:29 +01:00
|
|
|
To finish this challenge, it's necessary to use the __/s__ character class in your regexp pattern.
|
2018-10-04 14:47:55 +01:00
|
|
|
|
2018-12-21 02:14:29 +01:00
|
|
|
__\s__ matches a single white space character. (including space, tab, form feed, line feed and other Unicode spaces.
|
2018-10-04 14:47:55 +01:00
|
|
|
|
2018-12-21 02:14:29 +01:00
|
|
|
For example:
|
|
|
|
```javascript
|
2019-07-24 00:59:27 -07:00
|
|
|
/\s\w*/;
|
2018-12-21 02:14:29 +01:00
|
|
|
// matches " bar" in "foo bar".
|
|
|
|
```
|
|
|
|
|
|
|
|
__important:__ Characters are case sensitive in regexp. __\S__ matches a single character other than white space.
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-12-21 02:14:29 +01:00
|
|
|
```javascript
|
|
|
|
let sample = "Whitespace is important in separating words";
|
|
|
|
let countWhiteSpace = /\s/g; // Change this line
|
|
|
|
let result = sample.match(countWhiteSpace);
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
</details>
|