HackerRank Matching Specific Characters Solution

Hello Programmers, In this post, you will learn how to solve HackerRank Matching Specific Characters 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 Specific Characters Solution
HackerRank Matching Specific Characters Solution

HackerRank Matching Specific Characters Solution

[]
The character class [ ] matches only one out of several characters placed inside the square brackets.

HackerRank Matching Specific Characters Solution

Task

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

  • S must be of length: 6
  • First character: 12 or 3
  • Second character: 12 or 0
  • Third character: xs or 0
  • Fourth character: 30 , A or a
  • Fifth character: xs or u
  • Sixth character: . or ,

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

HackerRank Matching Specific Characters Solution in Cpp

HackerRank Matching Specific Characters Solution in Java

public class Solution {    

    public static void main(String[] args) {
        
        Regex_Test tester = new Regex_Test();
        tester.checker("^[123][120][xs0][30Aa][xsu][\\.\\,]$"); // Use \\ instead of using \ 
    
    }
}

HackerRank Matching Specific Characters Solution in Python

Regex_Pattern = r'^[1-3][0-2][xs0][30Aa][xsu][.,]$'	# Do not delete 'r'.

Matching Specific Characters Solution in JavaScript

var Regex_Pattern = /^[123][120][xs0][30Aa][xsu][.,]$/; //Do not delete '/'. Replace __________ with your regex. 

Matching Specific Characters Solution in PHP

$Regex_Pattern = "/^[123][120][xs0][30Aa][xsu][.,]$/"; //Do not delete '/'. Replace __________ with your regex. 

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

Sharing Is Caring