Matching Start & End – HackerRank Solution

In this post, we will solve Matching Start & End HackerRank Solution. This problem (Matching Start & End) is a part of HackerRank Regex series.

Objective

^
The ^ symbol matches the position at the start of a string.

$
The $ symbol matches the position at the end of a string.

Task

You have a test string S. Your task is to match the pattern Xxxxx.
Here, x denotes a word character, and X denotes a digit.
S must start with a digit X and end with . symbol.
S should be 6 characters long only.

Note

This is a regex only challenge. You are not required to write code.
You have to fill the regex pattern in the blank (_________).

Solution – Matching Start & End – HackerRank Solution

Python

Regex_Pattern = r"^\d\S{4}\.$"  # Do not delete 'r'.


import re

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

Note: This problem (Matching Start & End) 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 *