* 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.3 KiB
1.3 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db4367417b2b2512b92 | 提取匹配项 | 1 | 301340 | extract-matches |
--description--
到目前为止,只是检查了一个匹配模式是否存在于字符串中。还可以使用.match()
方法来提取找到的实际匹配项。
可以使用字符串来调用.match()
方法,并在括号内传入正则表达式。以下是一个示例:
"Hello, World!".match(/Hello/);
// Returns ["Hello"]
let ourStr = "Regular expressions";
let ourRegex = /expressions/;
ourStr.match(ourRegex);
// Returns ["expressions"]
--instructions--
利用.match()
方法提取单词coding
。
--hints--
结果
应该包含单词coding
。
assert(result.join() === 'coding');
你的正则表达式codingRegex
应该搜寻coding
。
assert(codingRegex.source === 'coding');
你应该使用.match()
方法。
assert(code.match(/\.match\(.*\)/));
--seed--
--seed-contents--
let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /change/; // Change this line
let result = extractStr; // Change this line
--solutions--
let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /coding/; // Change this line
let result = extractStr.match(codingRegex); // Change this line