-
Notifications
You must be signed in to change notification settings - Fork 183
/
03 - Alternative Matching.py
43 lines (36 loc) · 1.34 KB
/
03 - Alternative Matching.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/alternative-matching/problem
# Difficulty: Easy
# Max Score: 20
# Language: Python
# ========================
# Solution
# ========================
import re
regex_pattern = r'^(Mr?s|[MDE]r)\.[a-zA-Z]+$'
# Regex Pattern:
# .
# ├── ^
# │ └── Denotes the start of the line
# ├── (Mr?s|[MDE]r)
# │ ├── Mr?s
# │ │ ├── M - Denotes an 'M' character
# │ │ ├── r - Denotes an 'r' character
# │ │ ├── ? - Denotes the above expression for 0 and 1 times
# │ │ └── s - Denotes an 's' character
# │ ├── | - Denotes a boolean OR operator
# │ ├── [MDE] - Denotes any single character included in the list 'MDE'
# │ └── r - Denotes an 'r' character
# ├── \.
# │ └── Denotes a '.' character
# ├── [a-zA-Z]+
# │ ├── a-z - Denotes a single character in the range of a and z
# │ ├── A-Z - Denotes a single character in the range of A and Z
# │ └── + - Denotes the above expression for 1 or unlimited times, same as {1,}
# └── $
# └── Denotes the end of the line
# Example: Mr.Robot
# Example: Mr.Bean
print(str(bool(re.search(regex_pattern, input()))).lower())