Matching Zero Or More Repetitions – HackerRank Solution

In this post, we will solve Matching Zero Or More Repetitions HackerRank Solution. This problem (Matching Zero or More Repetitions) is a part of HackerRank Regex series.

Objective

*
The * tool will match zero or more repetitions of character/character class/group.

For Example:

w* : It will match the character w 0 or more times.
[xyz]* : It will match the characters xy or z 0 or more times.
\d* : It will match any digit 0 or more 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 2 or more digits.
  • After that, S should have 0 or more lowercase letters.
  • S should end with 0 or more uppercase letters

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 Zero Or More Repetitions – HackerRank Solution

Python

Regex_Pattern = r'^\d{2,}[a-z]*[A-Z]*$' # Do not delete 'r'.


import re

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

Note: This problem (Matching Zero Or More 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 *