HackerRank Matching {x} Repetitions Solution

Hello Programmers, In this post, you will know how to solve the HackerRank Matching {x} Repetitions Solution. This problem is a part of the Regex HackerRank Series.

HackerRank Matching {x} Repetitions Solution
HackerRank Matching {x} Repetitions Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

HackerRank Matching {x} Repetitions Solutions

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

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, yz}. 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 (_________).

HackerRank Matching {x} Repetitions Solutions in Cpp

HackerRank Matching {x} Repetitions Solutions in Java

public class Solution {    
    public static void main(String[] args) {
        Regex_Test tester = new Regex_Test();
        tester.checker("^[a-zA-Z02468]{40}(?:[13579]|\\s){5}$"); // Use \\ instead of using \ 

HackerRank Matching {x} Repetitions Solutions in Python

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

HackerRank Matching {x} Repetitions Solutions in JavaScript

var Regex_Pattern = /^[a-zA-Z02468]{40}[13579\s]{5}$/;

HackerRank Matching {x} Repetitions Solutions in PHP

$Regex_Pattern = "/^[a-zA-Z02468]{40}[\s13579]{5}$/"; //Do not delete '/'. Replace __________ with your regex. 

Disclaimer: This problem (Matching {x} Repetitions) is generated by HackerRank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: HackerRank Matching {x, y} Repetitions Solution

Leave a Reply

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