3.3 KiB
3.3 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db8367417b2b2512ba3 | Match Whitespace | 1 | Совпадение пробелов |
Description
\s
, которая является строчной s
. Этот шаблон не только соответствует пробелу, но также возвращает карету, вкладку, форму и новые символы строки. Вы можете считать это похожим на класс символов [ \r\t\f\n\v]
. let whiteSpace = "Пробел. Пробел везде!"
пусть пространство Regex = / \ s / g;
whiteSpace.match (spaceRegex);
// Возвращает ["", ""]
Instructions
countWhiteSpace
для поиска нескольких символов пробела в строке. Tests
tests:
- text: В вашем регулярном выражении должен использоваться глобальный флаг.
testString: 'assert(countWhiteSpace.global, "Your regex should use the global flag.");'
- text: Вашему регулярному выражению следует использовать сокращенный символ
testString: 'assert(/\\s/.test(countWhiteSpace.source), "Your regex should use the shorthand character <code>\s</code> to match all whitespace characters.");'
- text: Ваше регулярное выражение должно найти восемь пробелов в <code>"Men are from Mars and women are from Venus."</code>
testString: 'assert("Men are from Mars and women are from Venus.".match(countWhiteSpace).length == 8, "Your regex should find eight spaces in <code>"Men are from Mars and women are from Venus."</code>");'
- text: 'Ваше регулярное выражение должно найти три пробела в <code>"Space: the final frontier."</code>'
testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3, "Your regex should find three spaces in <code>"Space: the final frontier."</code>");'
- text: Ваше регулярное выражение не должно <code>"MindYourPersonalSpace"</code> пробелов в <code>"MindYourPersonalSpace"</code>
testString: 'assert("MindYourPersonalSpace".match(countWhiteSpace) == null, "Your regex should find no spaces in <code>"MindYourPersonalSpace"</code>");'
Challenge Seed
let sample = "Whitespace is important in separating words";
let countWhiteSpace = /change/; // Change this line
let result = sample.match(countWhiteSpace);
Solution
// solution required