Matching Same Text Again & Again – HackerRank Solution

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

Contents

Objective

\group_number
This tool (\1Â references the first capturing group) matches the same text as previously matched by the capturing group.

For Example:

(\d)\1: It can matchÂ `00`,Â `11`,Â `22`,Â `33`,Â `44`,Â `55`,Â `66`,Â `77`,Â `88`Â orÂ `99`.

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

• SÂ must be of length:Â `20`
• 1stÂ character:Â `lowercase letter`.
• 2ndÂ character:Â `word character`.
• 3rdÂ character:Â `whitespace character`.
• 4thÂ character:Â `non word character`.
• 5thÂ character:Â `digit`.
• 6thÂ character:Â `non digit`.
• 7thÂ character:Â `uppercase letter`.
• 8thÂ character:Â `letter`Â (either lowercase or uppercase).
• 9thÂ character:Â `vowel`Â (a, e, i , o , u, A, E, I, O or U).
• 10thÂ character:Â `non whitespace character`.
• 11thÂ character: should be same asÂ `1st character`.
• 12thÂ character: should be same asÂ `2nd character`.
• 13thÂ character: should be same asÂ `3rd character`.
• 14thÂ character: should be same asÂ `4th character`.
• 15thÂ character: should be same asÂ `5th character`.
• 16thÂ character: should be same asÂ `6th character`.
• 17thÂ character: should be same asÂ `7th character`.
• 18thÂ character: should be same asÂ `8th character`.
• 19thÂ character: should be same asÂ `9th character`.
• 20thÂ character: should be same asÂ `10th character`.

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 Same Text Again & Again – HackerRank Solution

Python

```Regex_Pattern = r'([a-z]\w\s\W\d\D[A-Z][a-zA-Z][aeiouAEIOU]\S)\1'

import re

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

Note: This problem (Matching Same Text Again & Again) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.