-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy path02 - Matching {x, y} Repetitions.py
More file actions
38 lines (31 loc) · 1.12 KB
/
02 - Matching {x, y} Repetitions.py
File metadata and controls
38 lines (31 loc) · 1.12 KB
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
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/matching-x-y-repetitions/problem
# Difficulty: Easy
# Max Score: 20
# Language: Python
# ========================
# Solution
# ========================
import re
regex_pattern = r'^\d{1,2}[a-zA-z]{3,}[.]{0,3}$'
# Regex Pattern:
# .
# ├── ^
# │ └── Denotes the start of the line
# ├── \d{1,2}
# │ ├── \d - Denotes a digit (equal to [0-9])
# │ └── {1,2}- Denotes the above expression for 1 or 2 times
# ├── [a-zA-z]{3,}
# │ ├── 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
# │ └── {3,} - Denotes the above expression for 3 or unlimited times
# ├── [.]{0,3}
# │ ├── [.] - Denotes a '.' character
# │ └── {0,3} - Denotes the above expression for 0 up to 3 times
# └── $
# └── Denotes the end of the line
# Example: 0aAa.
# Example: 3threeormorealphabets.
print(str(bool(re.search(regex_pattern, input()))).lower())