Matching Digits & Non-Digit Characters – HackerRank Solution

In this post, we will solve Matching Digits & Non-Digit Characters HackerRank Solution. This problem (Matching Digits & Non-Digit Characters) is a part of HackerRank Regex series.

Objective

\d
The expression \d matches any digit [0 – 9].

\D
The expression \D matches any character that is not a digit.

Task

You have a test string S. Your task is to match the pattern xxXxxXxxxx
Here x denotes a digit character, and X denotes a non-digit character.

Note

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

Solution – Matching Digits & Non-Digit Characters – HackerRank Solution

Python

Regex_Pattern = r"\d\d(.)\d\d(.)\d\d\d\d"   # Do not delete 'r'.


import re

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

Note: This problem (Matching Digits & Non-Digit Characters) 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 *