2018-09-30 23:01:58 +01:00
---
id: 587d7db9367417b2b2512ba7
title: Specify Exact Number of Matches
challengeType: 1
---
## Description
< section id = 'description' >
You can specify the lower and upper number of patterns with < code > quantity specifiers< / code > using curly brackets. Sometimes you only want a specific number of matches.
To specify a certain number of patterns, just have that one number between the curly brackets.
For example, to match only the word < code > "hah"< / code > with the letter < code > a< / code > < code > 3< / code > times, your regex would be < code > /ha{3}h/< / code > .
< blockquote > let A4 = "haaaah";< br > let A3 = "haaah";< br > let A100 = "h" + "a".repeat(100) + "h";< br > let multipleHA = /ha{3}h/;< br > multipleHA.test(A4); // Returns false< br > multipleHA.test(A3); // Returns true< br > multipleHA.test(A100); // Returns false< / blockquote >
< / section >
## Instructions
< section id = 'instructions' >
Change the regex < code > timRegex< / code > to match the word < code > "Timber"< / code > only when it has four letter < code > m< / code > 's.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: Your regex should use curly brackets.
2018-10-20 21:02:47 +03:00
testString: assert(timRegex.source.match(/{.*?}/).length > 0, 'Your regex should use curly brackets.');
2018-10-04 14:37:37 +01:00
- text: Your regex should not match < code > "Timber"</ code >
2018-10-20 21:02:47 +03:00
testString: assert(!timRegex.test("Timber"), 'Your regex should not match < code > "Timber"< / code > ');
2018-10-04 14:37:37 +01:00
- text: Your regex should not match < code > "Timmber"</ code >
2018-10-20 21:02:47 +03:00
testString: assert(!timRegex.test("Timmber"), 'Your regex should not match < code > "Timmber"< / code > ');
2018-10-04 14:37:37 +01:00
- text: Your regex should not match < code > "Timmmber"</ code >
2018-10-20 21:02:47 +03:00
testString: assert(!timRegex.test("Timmmber"), 'Your regex should not match < code > "Timmmber"< / code > ');
2018-10-04 14:37:37 +01:00
- text: Your regex should match < code > "Timmmmber"</ code >
2018-10-20 21:02:47 +03:00
testString: assert(timRegex.test("Timmmmber"), 'Your regex should match < code > "Timmmmber"< / code > ');
2018-10-04 14:37:37 +01:00
- text: Your regex should not match < code > "Timber"</ code > with 30 < code > m</ code > 's in it.
2018-10-20 21:02:47 +03:00
testString: assert(!timRegex.test("Ti" + "m".repeat(30) + "ber"), 'Your regex should not match < code > "Timber"</ code > with 30 < code > m</ code > \'s in it.');
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
let timStr = "Timmmmber";
let timRegex = /change/; // Change this line
let result = timRegex.test(timStr);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-03-05 23:42:55 +05:30
let timStr = "Timmmmber";
let timRegex = /Tim{4}ber/; // Change this line
let result = timRegex.test(timStr);
2018-09-30 23:01:58 +01:00
```
< / section >