freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../regular-expressions/match-letters-of-the-alphab...

2.2 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7db5367417b2b2512b96 Match Letters of the Alphabet 1 匹配字母的字母

Description

您了解了如何使用character sets来指定要匹配的一组字符,但是当您需要匹配大范围的字符(例如,字母表中的每个字母)时,这是很多类型。幸运的是,有一个内置功能,使这简短。在character set ,您可以使用hyphen字符来定义要匹配的hyphen范围: - 。例如,要匹配小写字母ae您将使用[ae]
让catStr =“猫”;
让batStr =“蝙蝠”;
让matStr =“mat”;
让bgRegex = / [ae] at /;
catStr.matchbgRegex; //返回[“cat”]
batStr.matchbgRegex; //返回[“bat”]
matStr.matchbgRegex; //返回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