* fix: convert js algorithms and data structures * fix: revert some blocks back to blockquote * fix: reverted comparison code block to blockquotes * fix: change js to json Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: convert various section to triple backticks * fix: Make the formatting consistent for comparisons
2.6 KiB
2.6 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
587d7db9367417b2b2512ba4 | Match Non-Whitespace Characters | 1 |
Description
\s
, with a lowercase s
. You can also search for everything except whitespace.
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]
.
let whiteSpace = "Whitespace. Whitespace everywhere!"
let nonSpaceRegex = /\S/g;
whiteSpace.match(nonSpaceRegex).length; // Returns 32
Instructions
countNonWhiteSpace
to look for multiple non-whitespace characters in a string.
Tests
tests:
- text: Your regex should use the global flag.
testString: assert(countNonWhiteSpace.global, 'Your regex should use the global flag.');
- text: Your regex should use the shorthand character
testString: assert(/\\S/.test(countNonWhiteSpace.source), 'Your regex should use the shorthand character <code>\S/code> to match all non-whitespace characters.');
- text: Your regex should find 35 non-spaces in <code>"Men are from Mars and women are from Venus."</code>
testString: assert("Men are from Mars and women are from Venus.".match(countNonWhiteSpace).length == 35, 'Your regex should find 35 non-spaces in <code>"Men are from Mars and women are from Venus."</code>');
- text: 'Your regex should find 23 non-spaces in <code>"Space: the final frontier."</code>'
testString: 'assert("Space: the final frontier.".match(countNonWhiteSpace).length == 23, ''Your regex should find 23 non-spaces in <code>"Space: the final frontier."</code>'');'
- text: Your regex should find 21 non-spaces in <code>"MindYourPersonalSpace"</code>
testString: assert("MindYourPersonalSpace".match(countNonWhiteSpace).length == 21, 'Your regex should find 21 non-spaces in <code>"MindYourPersonalSpace"</code>');
Challenge Seed
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /change/; // Change this line
let result = sample.match(countNonWhiteSpace);
Solution
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /\S/g; // Change this line
let result = sample.match(countNonWhiteSpace);