2018-10-04 14:47:55 +01:00
---
title: Specify Exact Number of Matches
---
2019-07-24 00:59:27 -07:00
# Specify Exact Number of Matches
2018-10-04 14:47:55 +01:00
2019-07-24 00:59:27 -07:00
---
## Hints
### Hint 1
2018-11-07 04:48:58 +01:00
We see that the answer is simply finding 4 m's in a row. The first anwser would be to match EXACTLY 4 times the character so we shall implement as following:
2019-07-24 00:59:27 -07:00
```javascript
let timRegex = /m{4}/;
```
2018-11-07 04:48:58 +01:00
This solution is incorrect because you wont pass the final test case ("Timber" with 30 m's in it) as there are multiple times mmmm in a row of 30 m.
You should try to get **no more than** ** *(4 times m) mmmm***.
2018-10-04 14:47:55 +01:00
2019-07-24 00:59:27 -07:00
### Hint 2
2018-11-07 04:48:58 +01:00
Based on the above I will try to specify exactly the characters before and after 4 times m!
***Remember:*** e.g. /b/ is a string literal for the word b so what if before and after mmmm we add ALL missing letters?
2019-07-24 00:59:27 -07:00
---
## Solutions
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-11-07 04:48:58 +01:00
From hint 1 we defined how to find mmmm in the timStr. From hint 2 we observe that we need to find the word Timmmmber=Tim{4}ber.
We simpply add the exact word in our timRegex value and the final result is:
2019-07-24 00:59:27 -07:00
```javascript
2018-11-07 04:48:58 +01:00
let timStr = "Timmmmber";
let timRegex = /Tim{4}ber/; // Change this line
let result = timRegex.test(timStr);
2019-07-24 00:59:27 -07:00
```
< / details >
2018-10-04 14:47:55 +01:00