2018-10-10 18:03:03 -04:00
---
id: 587d7db9367417b2b2512ba7
2021-02-06 04:42:36 +00:00
title: Specify Exact Number of Matches
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 301365
2021-01-13 03:31:00 +01:00
dashedName: specify-exact-number-of-matches
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 can specify the lower and upper number of patterns with quantity specifiers using curly brackets. Sometimes you only want a specific number of matches.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
To specify a certain number of patterns, just have that one number between the curly brackets.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
For example, to match only the word `"hah"` with the letter `a` `3` times, your regex would be `/ha{3}h/` .
2020-08-04 15:14:01 +08:00
```js
let A4 = "haaaah";
let A3 = "haaah";
let A100 = "h" + "a".repeat(100) + "h";
let multipleHA = /ha{3}h/;
multipleHA.test(A4); // Returns false
multipleHA.test(A3); // Returns true
multipleHA.test(A100); // Returns false
```
2020-12-16 00:37:30 -07:00
# --instructions--
2021-02-06 04:42:36 +00:00
Change the regex `timRegex` to match the word `"Timber"` only when it has four letter `m` 's.
2020-12-16 00:37:30 -07:00
# --hints--
2021-02-06 04:42:36 +00:00
Your regex should use curly brackets.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(timRegex.source.match(/{.*?}/).length > 0);
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should not match `"Timber"`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
timRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(!timRegex.test('Timber'));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should not match `"Timmber"`
2018-10-10 18:03:03 -04:00
```js
2021-02-06 04:42:36 +00:00
timRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(!timRegex.test('Timmber'));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should not match `"Timmmber"`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
timRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(!timRegex.test('Timmmber'));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should match `"Timmmmber"`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
timRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(timRegex.test('Timmmmber'));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex should not match `"Timber"` with 30 `m` 's in it.
2018-10-10 18:03:03 -04:00
```js
2021-02-06 04:42:36 +00:00
timRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(!timRegex.test('Ti' + 'm'.repeat(30) + 'ber'));
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 timStr = "Timmmmber";
let timRegex = /change/; // Change this line
let result = timRegex.test(timStr);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let timStr = "Timmmmber";
let timRegex = /Tim{4}ber/; // Change this line
let result = timRegex.test(timStr);
```