--- id: 587d7db7367417b2b2512b9f title: Match All Letters and Numbers challengeType: 1 videoUrl: '' localeTitle: 匹配所有字母和数字 --- ## Description
使用字符类,您可以使用[az]搜索字母表中的所有字母。这种字符类很常见,它有一个快捷方式,虽然它还包含一些额外的字符。 JavaScript中与字母表匹配的最接近的字符类是\w 。此快捷方式等于[A-Za-z0-9_] 。此字符类匹配大写和小写字母加数字。注意,此字符类还包括下划线字符( _ )。
让longHand = / [A-Za-z0-9 _] + /;
让shortHand = / \ w + /;
让数字=“42”;
let varNames =“important_var”;
longHand.test(数字); //返回true
shortHand.test(数字); //返回true
longHand.test(varNames); //返回true
shortHand.test(varNames); //返回true
这些快捷方式字符类也称为shorthand character classes
## Instructions
使用速记字符类\w来计算各种引号和字符串中的字母数字字符数。
## Tests
```yml tests: - text: 你的正则表达式应该使用全局标志。 testString: assert(alphabetRegexV2.global); - text: 你的正则表达式应该使用速记字符 testString: assert(/\\w/.test(alphabetRegexV2.source)); - text: 你的正则表达式应该在"The five boxing wizards jump quickly."找到31个字母数字字符"The five boxing wizards jump quickly." testString: assert("The five boxing wizards jump quickly.".match(alphabetRegexV2).length === 31); - text: 你的正则表达式应该在"Pack my box with five dozen liquor jugs."找到32个字母数字字符"Pack my box with five dozen liquor jugs." testString: assert("Pack my box with five dozen liquor jugs.".match(alphabetRegexV2).length === 32); - text: 你的正则表达式应该在"How vexingly quick daft zebras jump!"找到30个字母数字字符"How vexingly quick daft zebras jump!" testString: assert("How vexingly quick daft zebras jump!".match(alphabetRegexV2).length === 30); - text: 你的正则表达式应该在"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."找到36个字母数字字符"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ." testString: assert("123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.".match(alphabetRegexV2).length === 36); ```
## Challenge Seed
```js let quoteSample = "The five boxing wizards jump quickly."; let alphabetRegexV2 = /change/; // Change this line let result = quoteSample.match(alphabetRegexV2).length; ```
## Solution
```js // solution required ```