HackerRank Matching Character Ranges Solution

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

In the context of a regular expression (RegEx), character class is a set of characters enclosed within square brackets that allows you to match one character in the set.

A hyphen (`-`) inside a character class specifies a range of characters where the left and right operands are the respective lower and upper bounds of the range. For example:

• [a – z] is the same as [abcdefghijklmnopqrstuvwxyz].
• [A – Z] is the same as [ABCDEFGHIJKLMNOPQRSTUVWXYZ].
• [0 – 9] is the same as [0123456789].

In addition, if you use a caret (`^`) as the first character inside a character class, it will match anything that is not in that range. For example, [^0-9] matches any character that is not a digit in the inclusive range from 0 to 9. It’s important to note that, when used outside of (immediately preceding) a character or character class, the caret matches the first character in the string against that character or set of characters.

Write a RegEx that will match a string satisfying the following conditions:

• The string’s length is >= 5.
• The first character must be a lowercase English alphabetic character.
• The second character must be a positive digit. Note that we consider zero to be neither positive nor negative.
• The third character must not be a lowercase English alphabetic character.
• The fourth character must not be an uppercase English alphabetic character.
• The fifth character must be an uppercase English alphabetic character.

In the editor below, replace the blank (`_________`) with a RegEx pattern satisfying the criteria above. This is a RegExonly challenge, so you are not required to write any additional code.

HackerRank Matching Character Ranges Solution in Java

```public class Solution {

public static void main(String[] args) {

Regex_Test tester = new Regex_Test();
tester.checker("^[a-z][1-9][^a-z][^A-Z][A-Z].*"); // Use \\ instead of using \

}
}```

HackerRank Matching Character Ranges Solution in Python

`Regex_Pattern = r'^[a-z][1-9][^a-z][^A-Z][A-Z]'	# Do not delete 'r'.`

HackerRank Matching Character Ranges Solution in JavaScript

`var Regex_Pattern = /^[a-z][1-9][^a-z][^A-Z][A-Z]/; //Do not delete '/'. Replace __________ with your regex. `

HackerRank Matching Character Ranges Solution in PHP

`\$Regex_Pattern = "/^[a-z][1-9][^a-z][^A-Z][A-Z]/"; //Do not delete '/'. Replace __________ with your regex. `

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

Sharing Is Caring