* 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.8 KiB
1.8 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
5c3dda8b4d8df89bea71600f | 检查混合字符组 | 1 | 301339 | check-for-mixed-grouping-of-characters |
--description--
有时候我们想使用正则表达式里的括号 ()
来检查字符组。
如果想在字符串找到 Penguin
或 Pumpkin
,可以这个正则表达式:/P(engu|umpk)in/g
。
然后使用 test()
方法检查 test 字符串里面是否包含字符组。
let testStr = "Pumpkin";
let testRegex = /P(engu|umpk)in/g;
testRegex.test(testStr);
// Returns true
--instructions--
完善正则表达式,使其以区分大小写的方式检查 Franklin Roosevelt
或 Eleanor Roosevelt
的名字,并且应该忽略 middle names。
然后完善代码,使创建的正则检查 myString
,根据正则是否匹配返回 true
或 false
。
--hints--
正则 myRegex
测试 Franklin D. Roosevelt
应该返回 true
。
myRegex.lastIndex = 0;
assert(myRegex.test('Franklin D. Roosevelt'));
正则 myRegex
测试 Eleanor Roosevelt
应该返回 true
。
myRegex.lastIndex = 0;
assert(myRegex.test('Eleanor Roosevelt'));
正则 myRegex
测试 Franklin Rosevelt
应该返回 false
。
myRegex.lastIndex = 0;
assert(!myRegex.test('Franklin Rosevelt'));
应该使用 .test()
来测试正则。
assert(code.match(/myRegex.test\(\s*myString\s*\)/));
result 应该返回 true
。
assert(result === true);
--seed--
--seed-contents--
let myString = "Eleanor Roosevelt";
let myRegex = /False/; // Change this line
let result = false; // Change this line
// After passing the challenge experiment with myString and see how the grouping works
--solutions--
let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/;
let result = myRegex.test(myString);