Excluding Specific Characters – HackerRank Solution

In this post, we will solve Excluding Specific Characters HackerRank Solution. This problem (Excluding Specific Characters) is a part of HackerRank Regex series.

Contents

Objective

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

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

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Â (a, e, i, oÂ orÂ u).
• Third character shouldÂ notÂ beÂ b,Â c,Â DÂ orÂ F.
• Fourth character shouldÂ notÂ be aÂ whitespace characterÂ ( \r, \n, \t, \f or <space> ).
• Fifth character shouldÂ notÂ be aÂ uppercase vowelÂ (A, E, I, OÂ 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 (_________).

Solution – Excluding Specific Characters – HackerRank Solution

Python

Regex_Pattern = r'^[^\d][^aeiou][^bcDF][^\s][^AEIOU][^.,]\$' # Do not delete 'r'.

import re

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

Note: This problem (Excluding Specific Characters) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.