# Matching {x} Repetitions – HackerRank Solution

In this post, we will solve Matching {x} Repetitions HackerRank Solution. This problem (Matching {x} Repetitions) is a part of HackerRank Regex series.

Contents

## Objective

{x}
The toolÂ {x}Â will match exactlyÂ xÂ repetitions of character/character class/groups.

For Example:

w{3}Â : It will match the characterÂ `w`Â exactlyÂ 3Â times.
[xyz]{5}Â : It will match the string of lengthÂ 5Â consisting of characters {`x`,Â `y`,Â `z`}. For example it will matchÂ `xxxxx`,Â `xxxyy`Â andÂ `xyxyz`.
\d{4}Â : It will match any digit exactlyÂ 4Â times.

You have a test stringÂ S.
Your task is to write a regex that will matchÂ SÂ using the following conditions:

• SÂ must be of length equal toÂ `45`.
• The firstÂ 40Â characters should consist ofÂ `letters`(both lowercase and uppercase), or ofÂ `even digits`.
• The lastÂ 5Â characters should consist ofÂ `odd digits`Â orÂ `whitespace characters`.

Note

This is a regex only challenge. You are not required to write any code.
You have to fill the regex pattern in the blank (`_________`).

## Solution – Matching {x} Repetitions – HackerRank Solution

### Python

```Regex_Pattern = r'^[a-zA-Z02468]{40}[\s13579]{5}\$'  # Do not delete 'r'.

import re

print(str(bool(re.search(Regex_Pattern, input()))).lower())
```

Note: This problem (Matching {x} Repetitions) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.