2018-10-10 18:03:03 -04:00
---
id: 5d712346c441eddfaeb5bdef
2021-02-06 04:42:36 +00:00
title: Match All Numbers
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 18181
2021-01-13 03:31:00 +01:00
dashedName: match-all-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 shortcuts for common string patterns like alphanumerics. Another common pattern is looking for just digits or numbers.
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
The shortcut to look for digit characters is `\d` , with a lowercase `d` . This is equal to the character class `[0-9]` , which looks for a single character of any number between zero and nine.
2020-12-16 00:37:30 -07:00
# --instructions--
2021-02-06 04:42:36 +00:00
Use the shorthand character class `\d` to count how many digits are in movie titles. Written out numbers ("six" instead of 6) do not count.
2020-12-16 00:37:30 -07:00
# --hints--
2021-02-06 04:42:36 +00:00
Your regex should use the shortcut character to match digit characters
2020-12-16 00:37:30 -07:00
```js
assert(/\\d/.test(numRegex.source));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should use the global flag.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(numRegex.global);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find 1 digit in `"9"` .
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert('9'.match(numRegex).length == 1);
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should find 2 digits in `"Catch 22"` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert('Catch 22'.match(numRegex).length == 2);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find 3 digits in `"101 Dalmatians"` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert('101 Dalmatians'.match(numRegex).length == 3);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should find no digits in `"One, Two, Three"` .
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert('One, Two, Three'.match(numRegex) == null);
```
2021-02-06 04:42:36 +00:00
Your regex should find 2 digits in `"21 Jump Street"` .
2020-08-04 15:14:01 +08:00
2020-12-16 00:37:30 -07:00
```js
assert('21 Jump Street'.match(numRegex).length == 2);
2018-10-10 18:03:03 -04:00
```
2020-08-04 15:14:01 +08:00
2021-02-06 04:42:36 +00:00
Your regex should find 4 digits in `"2001: A Space Odyssey"` .
2020-12-16 00:37:30 -07:00
```js
assert('2001: A Space Odyssey'.match(numRegex).length == 4);
```
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
let movieName = "2001: A Space Odyssey";
let numRegex = /change/; // Change this line
let result = movieName.match(numRegex).length;
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let movieName = "2001: A Space Odyssey";
let numRegex = /\d/g; // Change this line
let result = movieName.match(numRegex).length;
```