* 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.5 KiB
1.5 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db3367417b2b2512b8e | 使用测试方法 | 1 | 301369 | using-the-test-method |
--description--
在编程语言中,正则表达式用于匹配指定的字符串。通过正则表达式创建匹配模式(规则)可以帮你完成指定匹配。
如果想要在字符串"The dog chased the cat"
中匹配到"the"
这个单词,可以使用如下正则表达式:/the/
。注意,正则表达式中不需要引号。
JavaScript 中有多种使用正则表达式的方法。测试正则表达式的一种方法是使用.test()
方法。.test()
方法会把编写的正则表达式和字符串(即括号内的内容)匹配,如果成功匹配到字符,则返回true
,反之,返回false
。
let testStr = "freeCodeCamp";
let testRegex = /Code/;
testRegex.test(testStr);
// Returns true
--instructions--
使用.test()
方法,检测字符串myString
是否符合正则表达式myRegex
定义的规则。
--hints--
你应该使用.test()
方法来检测正则表达式。
assert(code.match(/myRegex.test\(\s*myString\s*\)/));
你的返回结果应该为true
。
assert(result === true);
--seed--
--seed-contents--
let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex; // Change this line
--solutions--
let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex.test(myString); // Change this line