Matching One Or More Repetitions – HackerRank Solution

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

Contents

Objective

+
The + tool will match one or more repetitions of character/character class/group.

For Example:

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

Matching One Or More Repetitions – HackerRank Solution

Python

Regex_Pattern = r'^\d+[A-Z]+[a-z]+$'    # Do not delete 'r'.


import re

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

Note: This problem (Matching One 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 *