\s
, которая является строчной s
. Этот шаблон не только соответствует пробелу, но также возвращает карету, вкладку, форму и новые символы строки. Вы можете считать это похожим на класс символов [ \r\t\f\n\v]
. let whiteSpace = "Пробел. Пробел везде!"
пусть пространство Regex = / \ s / g;
whiteSpace.match (spaceRegex);
// Возвращает ["", ""]
countWhiteSpace
для поиска нескольких символов пробела в строке.
\s
to match all whitespace characters.
testString: assert(/\\s/.test(countWhiteSpace.source));
- 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);
- text: 'Your regex should find three spaces in "Space: the final frontier."
'
testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3);'
- text: Your regex should find no spaces in "MindYourPersonalSpace"
testString: assert("MindYourPersonalSpace".match(countWhiteSpace) == null);
```