2.5 KiB
2.5 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db8367417b2b2512ba3 | Match Whitespace | 1 | 匹配空白 |
Description
\s
搜索空格,这是一个小写的s
。此模式不仅匹配空格,还匹配回车符,制表符,换页符和换行符。你可以认为它类似于字符类[ \r\t\f\n\v]
。 让whiteSpace =“空白。到处都是空白!”
让spaceRegex = / \ 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>找到八个空格<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>找到三个空格<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: ''
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