2.0 KiB
2.0 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7dba367417b2b2512ba8 | Check for All or None | 1 | 检查全部或无 |
Description
?
。这将检查前一个元素中的零个或一个。您可以将此符号视为前一个元素是可选的。例如,美式英语和英式英语略有不同,您可以使用问号来匹配两种拼写。 让美国人=“颜色”;
让british =“color”;
让rainbowRegex = / colou?r /;
rainbowRegex.test(美国); //返回true
rainbowRegex.test(英国); //返回true
Instructions
favRegex
以匹配该单词的美国英语(收藏)和英国英语(收藏)版本。 Tests
tests:
- text: 你的正则表达式应该使用可选的符号, <code>?</code> 。
testString: 'assert(favRegex.source.match(/\?/).length > 0, "Your regex should use the optional symbol, <code>?</code>.");'
- text: 你的正则表达式应该匹配<code>"favorite"</code>
testString: 'assert(favRegex.test("favorite"), "Your regex should match <code>"favorite"</code>");'
- text: 你的正则表达式应该匹配<code>"favourite"</code>
testString: 'assert(favRegex.test("favourite"), "Your regex should match <code>"favourite"</code>");'
- text: 你的正则表达式不应该匹配<code>"fav"</code>
testString: 'assert(!favRegex.test("fav"), "Your regex should not match <code>"fav"</code>");'
Challenge Seed
let favWord = "favorite";
let favRegex = /change/; // Change this line
let result = favRegex.test(favWord);
Solution
// solution required