Javascript: Added hint to Match Non-Whitespace Characters (#19243)
* Javascript: Added hint to Match Non-Whitespace Characters Added hint to Match Non-Whitespace Characters (https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-non-whitespace-characters and https://guide.freecodecamp.org/certifications/javascript-algorithms-and-data-structures/regular-expressions/match-non-whitespace-characters/) * Replace match->matching * Fixed grammar
This commit is contained in:
committed by
Todd Chaffee
parent
9792d0976a
commit
9a1b895002
@ -1,10 +1,20 @@
|
||||
---
|
||||
title: Match Non-Whitespace Characters
|
||||
---
|
||||
|
||||
## Match Non-Whitespace Characters
|
||||
|
||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/javascript-algorithms-and-data-structures/regular-expressions/match-non-whitespace-characters/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
||||
|
||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||
|
||||
## Problem:
|
||||
|
||||
We need to change the regex ```countNonWhiteSpace``` to look for multiple non-whitespace characters in a string.
|
||||
|
||||
## Solution:
|
||||
|
||||
```js
|
||||
let sample = "Whitespace is important in separating words";
|
||||
let countNonWhiteSpace = /\S/g; // Change this line
|
||||
let result = sample.match(countNonWhiteSpace);
|
||||
```
|
||||
|
||||
## Explanation:
|
||||
|
||||
We use ```\S```, and this pattern will not match any of: whitespace, carriage return, tab, form feed, and new line characters. So we find all matching non-whitespace characters.
|
||||
|
Reference in New Issue
Block a user