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
quoteSample中的所有字母。 注意 alphabetRegex应该匹配35项。
testString: 'assert(result.length == 35, "Your regex alphabetRegex should match 35 items.");'
- text: 你的正则表达式alphabetRegex应该使用全局标志。
testString: 'assert(alphabetRegex.flags.match(/g/).length == 1, "Your regex alphabetRegex should use the global flag.");'
- text: 你的正则表达式alphabetRegex应该使用不区分大小写的标志。
testString: 'assert(alphabetRegex.flags.match(/i/).length == 1, "Your regex alphabetRegex should use the case insensitive flag.");'
```