\s
, which is a lowercase s
. This pattern not only matches whitespace, but also carriage return, tab, form feed, and new line characters. You can think of it as similar to the character class [ \r\t\f\n\v]
.
let whiteSpace = "Whitespace. Whitespace everywhere!"
let spaceRegex = /\s/g;
whiteSpace.match(spaceRegex);
// Returns [" ", " "]
countWhiteSpace
to look for multiple whitespace characters in a string.
\s
to match all whitespace characters.');
- text: Your regex should find eight spaces in "Men are from Mars and women are from Venus."
testString: assert("Men are from Mars and women are from Venus.".match(countWhiteSpace).length == 8, 'Your regex should find eight spaces in "Men are from Mars and women are from Venus."
');
- text: 'Your regex should find three spaces in "Space: the final frontier."
'
testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3, ''Your regex should find three spaces in "Space: the final frontier."
'');'
- text: Your regex should find no spaces in "MindYourPersonalSpace"
testString: assert("MindYourPersonalSpace".match(countWhiteSpace) == null, 'Your regex should find no spaces in "MindYourPersonalSpace"
');
```