-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex.py
99 lines (75 loc) · 2.78 KB
/
regex.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
--------------------------------
Exercises -- Regular Expressions
-------------------------------
Given the list of strings as input :
Kane#[email protected]
1) provide me the list of emails that do have special characters of #~`!
2) provide me the list of emails that start with numbers
3) provide me the list of emails that start with numbers followed by an underscore
4) provide me the list of emails that start with numbers followed by an underscore or small case characters
5) provide me the list of emails that start with numbers followed by an underscore or small case characters or large case characters
6) Provide me list of emails with only numbers before the @
7) Provide me list of emails with numbers anywhere before the @
"""
import re
l1 = ["[email protected]",
"Kane#[email protected]"]
for elem in my_list:
test_string = elem
result = re.search(".*[#~`!].*", test_string)
if result:
print("Email Id :" , result.group(0))
print(l1[0])
#1) provide me the list of emails that do have special characters of #~`!
for i in range(len(l1)):
str=l1[i]
a=re.search(".*[#~`!].*",str)
print(a)
#2) provide me the list of emails that start with numbers
for i in range(len(l1)):
str=l1[i]
a=re.search("^[0-9].*[a-z].*[@].*",str)
print(a)
#3) provide me the list of emails that start with numbers followed by an underscore
for i in range(len(l1)):
str=l1[i]
a=re.search("^\d+_.*[@].*",str)
print(a)
#4) provide me the list of emails that start with numbers followed by an underscore or small case characters
for i in range(len(l1)):
str=l1[i]
a=re.search("^[0-9]+[_a-z].*[@].*",str)
print(a)
#5) provide me the list of emails that start with numbers followed by an underscore or small case characters or large case characters
for i in range(len(l1)):
str=l1[i]
a=re.search("^[0-9]+[_a-zA-Z].*[@].*",str)
print(a)
#6) Provide me list of emails with only numbers before the @
for i in range(len(l1)):
str=l1[i]
a=re.search("^[0-9]+[@].*",str)
print(a)
#7) Provide me list of emails with numbers anywhere before the @
for i in range(len(l1)):
str=l1[i]
a=re.search("^.*\d+[@].*",str)
print(a)
# if a:
# print("Email Id :" , result.group(0))