* 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.6 KiB
1.6 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db4367417b2b2512b93 | 全局匹配 | 1 | 301342 | find-more-than-the-first-match |
--description--
到目前为止,只能提取或搜寻一次模式匹配。
let testStr = "Repeat, Repeat, Repeat";
let ourRegex = /Repeat/;
testStr.match(ourRegex);
// Returns ["Repeat"]
若要多次搜寻或提取模式匹配,可以使用g
标志。
let repeatRegex = /Repeat/g;
testStr.match(repeatRegex);
// Returns ["Repeat", "Repeat", "Repeat"]
--instructions--
使用正则表达式starRegex
,从字符串twinkleStar
中匹配到所有的"Twinkle"
单词并提取出来。
注意:
在正则表达式上可以有多个标志,比如/search/gi
。
--hints--
你的正则表达式starRegex
应该使用全局标志g
。
assert(starRegex.flags.match(/g/).length == 1);
你的正则表达式starRegex
应该使用忽略大小写标志i
。
assert(starRegex.flags.match(/i/).length == 1);
你的匹配应该匹配单词'Twinkle'
的两个匹配项。
assert(
result.sort().join() ==
twinkleStar
.match(/twinkle/gi)
.sort()
.join()
);
你的匹配结果
应该包含两个元素。
assert(result.length == 2);
--seed--
--seed-contents--
let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /change/; // Change this line
let result = twinkleStar; // Change this line
--solutions--
let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /twinkle/gi;
let result = twinkleStar.match(starRegex);