HackerRank Matching Same Text Again & Again Solution

Hello Programmers, In this post, you will learn how to solve HackerRank Matching Same Text Again & Again Solution. This problem is a part of the Regex HackerRank Series.

One more thing to add, don’t straight away look for the solutions, first try to solve the problems by yourself. If you find any difficulty after trying several times, then look for the solutions. We are going to solve the  Regex HackerRank Solutions using  CPP, JAVA, PYTHON, JavaScript & PHP Programming Languages.

HackerRank Matching Same Text Again & Again Solution
HackerRank Matching Same Text Again & Again Solution

HackerRank Matching Same Text Again & Again Solution

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

HackerRank Matching Same Text Again & Again Solution

For Example:

(\d)\1: It can match 0011, 22334455667788 or 99.

Task

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 (_________).

HackerRank Matching Same Text Again & Again Solution in Cpp

HackerRank Matching Same Text Again & Again Solution in Java

public class Solution {    

    public static void main(String[] args) {
        
        Regex_Test tester = new Regex_Test();
        tester.checker("^([a-z])(\\w)(\\s)(\\W)(\\d)(\\D)([A-Z])([A-Za-z])([aeiouAEIOU])(\\S)\\1\\2\\3\\4\\5\\6\\7\\8\\9\\10$"); // Use \\ instead of using \ 
    
    }
}

HackerRank Matching Same Text Again & Again Solution in Python

Regex_Pattern = r'([a-z])(\w)(\s)(\W)(\d)(\D)([A-Z])([A-Za-z])([aeiouAEIOU])(\S)\1\2\3\4\5\6\7\8\9\10'	# Do not delete 'r'.

Matching Same Text Again & Again Solution in JavaScript

var Regex_Pattern = /([a-z]{1})(\w{1})(\s{1})(\W{1})(\d{1})(\D{1})([A-Z]{1})([a-zA-Z]{1})([aeiouAEIOU]{1})(\S{1})\1\2\3\4\5\6\7\8\9\10/; //Do not delete '/'. Replace __________ with your regex. 

Matching Same Text Again & Again Solution in PHP

$Regex_Pattern = '/([a-z])([\w])([\s])([^\w])([0-9])([^0-9])([A-Z])([a-zA-Z])([aeiouAEIOU])([^\s])\1\2\3\4\5\6\7\8\9\10/'; //Do not delete '/'. Replace __________ with your regex. 

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

Sharing Is Caring

Leave a Comment