2.2 KiB
2.2 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db5367417b2b2512b96 | Match Letters of the Alphabet | 1 | 匹配字母的字母 |
Description
character sets
来指定要匹配的一组字符,但是当您需要匹配大范围的字符(例如,字母表中的每个字母)时,这是很多类型。幸运的是,有一个内置功能,使这简短。在character set
,您可以使用hyphen
字符来定义要匹配的hyphen
范围: -
。例如,要匹配小写字母a
到e
您将使用[ae]
。 让catStr =“猫”;
让batStr =“蝙蝠”;
让matStr =“mat”;
让bgRegex = / [ae] at /;
catStr.match(bgRegex); //返回[“cat”]
batStr.match(bgRegex); //返回[“bat”]
matStr.match(bgRegex); //返回null
Instructions
quoteSample
中的所有字母。 注意 务必匹配大写和小写字母。
Tests
tests:
- text: 你的正则表达式<code>alphabetRegex</code>应该匹配35项。
testString: 'assert(result.length == 35, "Your regex <code>alphabetRegex</code> should match 35 items.");'
- text: 你的正则表达式<code>alphabetRegex</code>应该使用全局标志。
testString: 'assert(alphabetRegex.flags.match(/g/).length == 1, "Your regex <code>alphabetRegex</code> should use the global flag.");'
- text: 你的正则表达式<code>alphabetRegex</code>应该使用不区分大小写的标志。
testString: 'assert(alphabetRegex.flags.match(/i/).length == 1, "Your regex <code>alphabetRegex</code> should use the case insensitive flag.");'
Challenge Seed
let quoteSample = "The quick brown fox jumps over the lazy dog.";
let alphabetRegex = /change/; // Change this line
let result = alphabetRegex; // Change this line
Solution
// solution required