HackerRank Excluding Specific Characters Solution

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

HackerRank Excluding Specific Characters Solution

[^]
The negated character class [^] matches any character that is not in the square brackets.

HackerRank Excluding Specific Characters Solution

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 6.
  • First character should not be a digit (1, 2, 3, 4, 5, 6, 7, 8, 9 or 0).
  • Second character should not be a lowercase vowel (aeio or u).
  • Third character should not be bcD or F.
  • Fourth character should not be a whitespace character ( \r, \n, \t, \f or <space> ).
  • Fifth character should not be a uppercase vowel (AEIO or U).
  • Sixth character should not be a . or , symbol.

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 Excluding Specific Characters Solution in Cpp

HackerRank Excluding Specific Characters Solution in Java

public class Solution {    

    public static void main(String[] args) {
        
        Regex_Test tester = new Regex_Test();
        tester.checker("^\\D[^aeiou][^bcDF][^\\r\\n\\t\\f\\s ][^AEIOU][^.,]$"); // Use \\ instead of using \ 
    
    }
}

HackerRank Excluding Specific Characters Solution in Python

Regex_Pattern = r'^\D[^aeiou][^bcDF]\S[^AEIOU][^\.,](?=$)'	# Do not delete 'r'.

HackerRank Excluding Specific Characters Solution in JavaScript

var Regex_Pattern = /^\D[^aeiou][^bcDF]\S[^AEIOU][^\.,]$/;

HackerRank Excluding Specific Characters Solution in PHP

$Regex_Pattern = "/^[^1,9][^aeiou][^bcDF][^\r\n\t\f\s][^AEIOU][^.,]$/"; //Do not delete '/'. Replace __________ with your regex. 

Disclaimer: This problem (Excluding 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