* 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>
1.4 KiB
1.4 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db7367417b2b2512b9e | 匹配字符串的末尾 | 1 | 301352 | match-ending-string-patterns |
--description--
在上一个挑战中,学习了使用^
符号来搜寻字符串开头的匹配模式。还有一种方法可以搜寻字符串末尾的匹配模式。
可以使用正则表达式的美元
符号$
来搜寻字符串的结尾。
let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
// Returns true
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);
// Returns false
--instructions--
使用$
在字符串caboose
的末尾匹配"caboose"
。
--hints--
你应该在正则表达式使用美元符号$
来搜寻'caboose'
。
assert(lastRegex.source == 'caboose$');
你的正则表达式不应该使用任何标志。
assert(lastRegex.flags == '');
你应该在字符串'The last car on a train is the caboose'
的末尾匹配'caboose'
。
assert(lastRegex.test('The last car on a train is the caboose'));
--seed--
--seed-contents--
let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);
--solutions--
let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);