-
Notifications
You must be signed in to change notification settings - Fork 183
/
01 - Matching Same Text Again & Again.py
43 lines (36 loc) · 1.61 KB
/
01 - Matching Same Text Again & Again.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/matching-same-text-again-again/problem
# Difficulty: Easy
# Max Score: 20
# Language: Python
# ========================
# Solution
# ========================
import re
regex_pattern = r'^([a-z]\w\s\W\d\D[A-Z][a-zA-Z][aieouAEIOU]\S)\1$'
# Regex Pattern:
# .
# ├── ^
# │ └── Denotes the start of the line
# ├── ([a-z]\w\s\W\d\D[A-Z][a-zA-Z][aieouAEIOU]\S)
# │ ├── [a-z]
# │ │ └── Denotes a single character in the range of a and z
# │ ├── \w - Denotes a word character (equal to [a-zA-Z0-9_])
# │ ├── \s - Denotes any whitespace character (equal to [\r\n\t\f\v ])
# │ ├── \W - Denotes any non-word character (equal to [^a-zA-Z0-9_])
# │ ├── \d - Denotes a digit (equal to [0-9])
# │ ├── \D - Denotes any character that is not a digit (equal to [^0-9])
# │ ├── [A-Z] - Denotes a single character in the range of A and Z
# │ ├── [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
# │ ├── [aieouAEIOU] - Denotes any single character included in the list 'aieouAEIOU'
# │ └── \S - Denotes any non-whitespace character (equal to [^\r\n\t\f\v ])
# ├── \1
# │ └── Denotes the first matching group
# └── $
# └── Denotes the end of the line
# Example: ab #1?AZa$ab #1?AZa$
print(str(bool(re.search(regex_pattern, input()))).lower())