* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2.0 KiB
2.0 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db9367417b2b2512ba4 | 匹配非空白字符 | 1 | 18210 | match-non-whitespace-characters |
--description--
已经学会了如何使用带有小写s
的缩写\s
来搜寻空白字符。还可以搜寻除了空格之外的所有内容。
使用\S
搜寻非空白字符,其中S
是大写。此匹配模式将不匹配空格、回车符、制表符、换页符和换行符。可以认为这类似于元字符[^\r\t\f\n\v]
。
let whiteSpace = "Whitespace. Whitespace everywhere!"
let nonSpaceRegex = /\S/g;
whiteSpace.match(nonSpaceRegex).length; // Returns 32
--instructions--
修改正则表达式countNonWhiteSpace
以查找字符串中的多个非空字符。
--hints--
你的正则表达式应该使用全局状态修正符。
assert(countNonWhiteSpace.global);
正则表达式应该使用元字符 \S/code> 来匹配所有的非空格字符。
assert(/\\S/.test(countNonWhiteSpace.source));
你的正则表达式应该在'Men are from Mars and women are from Venus.'
中匹配到 35 个非空白字符。
assert(
'Men are from Mars and women are from Venus.'.match(countNonWhiteSpace)
.length == 35
);
你的正则表达式应该在"Space: the final frontier."
中匹配到 23 个非空白字符。
assert('Space: the final frontier.'.match(countNonWhiteSpace).length == 23);
你的正则表达式应该在'MindYourPersonalSpace'
中匹配到 21 个非空白字符。
assert('MindYourPersonalSpace'.match(countNonWhiteSpace).length == 21);
--seed--
--seed-contents--
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /change/; // Change this line
let result = sample.match(countNonWhiteSpace);
--solutions--
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /\S/g; // Change this line
let result = sample.match(countNonWhiteSpace);