HackerRank Matching {x, y} Repetitions Solution

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

Ezoicreport this adHackerRank Matching {x, y} Repetitions Solution
HackerRank Matching {x, y} 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, y} Repetitions Solution

{x, y}
The {x,y} tool will match between x and y (both inclusive) repetitions of character/character class/group.

For Example:

w{3,5} : It will match the character w 34 or 5 times.
[xyz]{5,} :
It will match the character x, y or z 5 or more times.
\d{1, 4} :
It will match any digits 123, or 4 times.

Task

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

  • S should begin with 1 or 2 digits.
  • After that, S should have 3 or more letters (both lowercase and uppercase).
  • Then S should end with up to 3. symbol(s). You can end with 0 to 3. symbol(s), inclusively.

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

Ezoicreport this adHackerRank Matching {x, y} Repetitions Solutions in Cpp

HackerRank Matching {x, y} Repetitions Solutions in Java

public class Solution {    
    public static void main(String[] args) {
        
        Regex_Test tester = new Regex_Test();
        tester.checker("^\\d{1,2}[a-z|A-Z]{3,}[\\.]{0,3}$"); // Use \\ instead of using \ 
    
    }
}

HackerRank Matching {x, y} Repetitions Solutions in Python

Regex_Pattern = r'^\d{1,2}[a-zA-Z]{3,}\.{,3}$'   # Do not delete 'r'.
Ezoicreport this ad

HackerRank Matching {x, y} Repetitions Solutions in JavaScript

var Regex_Pattern = /^\d{1,2}[a-zA-Z]{3,}\.{0,3}$/;

HackerRank Matching {x, y} Repetitions Solutions in PHP

$Regex_Pattern = "/^[0-9]{1,2}[a-zA-Z]{3,}[\.]{0,3}$/"; //Do not delete '/'. Replace __________ with your regex. 

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

Next: HackerRank Detect HTML links Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad