In this post, we will solve Matching Specific Characters HackerRank Solution. This problem (Matching Specific Characters) is a part of HackerRank Regex series.
Objective
[]
The character class [ ]
matches only one out of several characters placed inside the square brackets.
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:
1
,2
or3
- Second character:
1
,2
or0
- Third character:
x
,s
or0
- Fourth character:
3
,0
,A
ora
- Fifth character:
x
,s
oru
- 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 (_________
).
Solution – Matching Specific Characters – HackerRank Solution
Python
Regex_Pattern = r'^[123][120][xs0][30Aa][xsu][.,]$' # Do not delete 'r'. import re print(str(bool(re.search(Regex_Pattern, input()))).lower())
Note: This problem (Matching Specific Characters) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.