55 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 587d7db5367417b2b2512b96
title: 匹配字母表中的字母
challengeType: 1
forumTopicId: 301354
---
# --description--
了解了如何使用`字符集`来指定要匹配的一组字符串,但是当需要匹配大量字符(例如,字母表中的每个字母)时,有一种写法可以让实现这个功能变得简短。
`字符集`中,可以使用`连字符``-`)来定义要匹配的字符范围。
例如,要匹配小写字母`a``e`,你可以使用`[a-e]`
```js
let catStr = "cat";
let batStr = "bat";
let matStr = "mat";
let bgRegex = /[a-e]at/;
catStr.match(bgRegex); // Returns ["cat"]
batStr.match(bgRegex); // Returns ["bat"]
matStr.match(bgRegex); // Returns null
```
# --instructions--
匹配字符串`quoteSample`中的所有字母。
**注意:**
一定要同时匹配大小写**字母**。\*\*\*\*
# --hints--
你的正则表达式`alphabetRegex`应该匹配 35 项。
```js
assert(result.length == 35);
```
你的正则表达式`alphabetRegex`应该使用全局标志。
```js
assert(alphabetRegex.flags.match(/g/).length == 1);
```
你的正则表达式`alphabetRegex`应该使用忽略大小写标志。
```js
assert(alphabetRegex.flags.match(/i/).length == 1);
```
# --solutions--