2018-10-10 18:03:03 -04:00
---
id: 587d7db8367417b2b2512ba0
2021-02-06 04:42:36 +00:00
title: Match Everything But Letters and Numbers
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 301353
2021-01-13 03:31:00 +01:00
dashedName: match-everything-but-letters-and-numbers
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
You've learned that you can use a shortcut to match alphanumerics `[A-Za-z0-9_]` using `\w` . A natural pattern you might want to search for is the opposite of alphanumerics.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
You can search for the opposite of the `\w` with `\W` . Note, the opposite pattern uses a capital letter. This shortcut is the same as `[^A-Za-z0-9_]` .
2020-08-04 15:14:01 +08:00
```js
let shortHand = /\W/;
let numbers = "42%";
let sentence = "Coding!";
numbers.match(shortHand); // Returns ["%"]
sentence.match(shortHand); // Returns ["!"]
```
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Use the shorthand character class `\W` to count the number of non-alphanumeric characters in various quotes and strings.
2020-12-16 00:37:30 -07:00
# --hints--
2021-02-06 04:42:36 +00:00
Your regex should use the global flag.
2020-12-16 00:37:30 -07:00
```js
assert(nonAlphabetRegex.global);
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should find 6 non-alphanumeric characters in `"The five boxing wizards jump quickly."` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(
'The five boxing wizards jump quickly.'.match(nonAlphabetRegex).length == 6
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should use the shorthand character to match characters which are non-alphanumeric.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(/\\W/.test(nonAlphabetRegex.source));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should find 8 non-alphanumeric characters in `"Pack my box with five dozen liquor jugs."`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(
'Pack my box with five dozen liquor jugs.'.match(nonAlphabetRegex).length == 8
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find 6 non-alphanumeric characters in `"How vexingly quick daft zebras jump!"`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(
'How vexingly quick daft zebras jump!'.match(nonAlphabetRegex).length == 6
);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find 12 non-alphanumeric characters in `"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."`
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(
'123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.'.match(nonAlphabetRegex)
.length == 12
);
2018-10-10 18:03:03 -04:00
```
2020-08-04 15:14:01 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
let quoteSample = "The five boxing wizards jump quickly.";
let nonAlphabetRegex = /change/; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let quoteSample = "The five boxing wizards_jump quickly.";
let nonAlphabetRegex = /\W/g; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;
```