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.


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 {xyz}. For example it will match xxxxxxxxyy 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.


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


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

import re

print(str(bool(, 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.

Leave a Comment

Your email address will not be published. Required fields are marked *