* 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.7 KiB
1.7 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db7367417b2b2512b9d | 匹配字符串的开头 | 1 | 301349 | match-beginning-string-patterns |
--description--
回顾一下之前的挑战,正则表达式可以用于查找多项匹配。还可以查询字符串中符合指定匹配模式的字符。
在之前的挑战中,使用字符集
中的插入
符号(^
)来创建一个否定字符集
,形如[^thingsThatWillNotBeMatched]
。在字符集
之外,插入
符号用于字符串的开头搜寻匹配模式。
let firstString = "Ricky is first and can be found.";
let firstRegex = /^Ricky/;
firstRegex.test(firstString);
// Returns true
let notFirst = "You can't find Ricky now.";
firstRegex.test(notFirst);
// Returns false
--instructions--
在正则表达式中使用^
符号,以匹配仅在字符串rickyAndCal
的开头出现的"Cal"
。
--hints--
你的正则表达式应该搜寻有一个大写字母的'Cal'
。
assert(calRegex.source == '^Cal');
你的正则表达式不应该使用任何标志。
assert(calRegex.flags == '');
你的正则表达式应该匹配字符串开头的'Cal'
。
assert(calRegex.test('Cal and Ricky both like racing.'));
你的正则表达式不应该匹配字符串中间的'Cal'
。
assert(!calRegex.test('Ricky and Cal both like racing.'));
--seed--
--seed-contents--
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /change/; // Change this line
let result = calRegex.test(rickyAndCal);
--solutions--
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /^Cal/; // Change this line
let result = calRegex.test(rickyAndCal);