2018-10-04 14:37:37 +01:00
---
id: 587d7db7367417b2b2512b9f
title: Match All Letters and Numbers
challengeType: 1
2019-08-05 09:17:33 -07:00
forumTopicId: 301346
2021-01-13 03:31:00 +01:00
dashedName: match-all-letters-and-numbers
2018-10-04 14:37:37 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
Using character classes, you were able to search for all letters of the alphabet with `[a-z]` . This kind of character class is common enough that there is a shortcut for it, although it includes a few extra characters as well.
The closest character class in JavaScript to match the alphabet is `\w` . This shortcut is equal to `[A-Za-z0-9_]` . This character class matches upper and lowercase letters plus numbers. Note, this character class also includes the underscore character (`_` ).
2019-05-17 06:20:30 -07:00
```js
let longHand = /[A-Za-z0-9_]+/;
let shortHand = /\w+/;
let numbers = "42";
let varNames = "important_var";
longHand.test(numbers); // Returns true
shortHand.test(numbers); // Returns true
longHand.test(varNames); // Returns true
shortHand.test(varNames); // Returns true
```
2019-10-27 15:45:37 -01:00
These shortcut character classes are also known as < dfn > shorthand character classes< / dfn > .
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
# --instructions--
Use the shorthand character class `\w` to count the number of alphanumeric characters in various quotes and strings.
# --hints--
Your regex should use the global flag.
```js
assert(alphabetRegexV2.global);
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex should use the shorthand character `\w` to match all characters which are alphanumeric.
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(/\\w/.test(alphabetRegexV2.source));
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Your regex should find 31 alphanumeric characters in `"The five boxing wizards jump quickly."`
2018-10-04 14:37:37 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(
'The five boxing wizards jump quickly.'.match(alphabetRegexV2).length === 31
);
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex should find 32 alphanumeric characters in `"Pack my box with five dozen liquor jugs."`
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
'Pack my box with five dozen liquor jugs.'.match(alphabetRegexV2).length ===
32
);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Your regex should find 30 alphanumeric characters in `"How vexingly quick daft zebras jump!"`
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
'How vexingly quick daft zebras jump!'.match(alphabetRegexV2).length === 30
);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Your regex should find 36 alphanumeric characters in `"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."`
```js
assert(
'123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.'.match(alphabetRegexV2)
.length === 36
);
```
# --seed--
## --seed-contents--
2018-10-04 14:37:37 +01:00
```js
2019-05-03 03:05:26 -07:00
let quoteSample = "The five boxing wizards jump quickly.";
2020-11-27 19:02:05 +01:00
let alphabetRegexV2 = /change/; // Change this line
2019-05-03 03:05:26 -07:00
let result = quoteSample.match(alphabetRegexV2).length;
2018-10-04 14:37:37 +01:00
```
2019-07-18 08:24:12 -07:00
2020-11-27 19:02:05 +01:00
# --solutions--
```js
let quoteSample = "The five boxing wizards jump quickly.";
let alphabetRegexV2 = /\w/g; // Change this line
let result = quoteSample.match(alphabetRegexV2).length;
```