-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprog53_Regular_Expressions.py
71 lines (57 loc) · 2.38 KB
/
prog53_Regular_Expressions.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
# Regular Expressions https://www.youtube.com/watch?v=g8u0wLvvPSs&list=PLu0W_9lII9agICnT8t4iYVSZ3eykIAOME&index=87
# List of the metacharacters
# . any charector except newline charector
# ^ starts with
# $ ends with
# * zero or more occurances
# + one or more occurances
# ?
# {} Exactly the specified no. of occurances
# [ ]
# \ signals a special sequence (can be used to escape special char)
# | either or
# ( ) capture and group
# \d :Matches any decimal digit; this is equivalent to the class [0-9].
# \D :Matches any non-digit character; this is equivalent to the class [^0-9].
# \s :Matches any whitespace character; this is equivalent to the class [ \t\n\r\f\v].
# \S :Matches any non-whitespace character; this is equivalent to the class [^ \t\n\r\f\v].
# \w :Matches any alphanumeric character; this is equivalent to the class [a-zA-Z0-9_].
# \W :Matches any non-alphanumeric character; this is equivalent to the class [^a-zA-Z0-9_].
import re
mytext = '''Reg. Office :
5, 2nd Floor, Dharma Market, Sector - 27,
Opp. SAB Mall, (near Metro Station Sector - 18)
Noida, Gautam Budha Nagar, Uttar Pradesh, 201301, India
Mobile:+91 75202-02200 , 09528468383
Email: director@gloxconsultancy.com , mukeshbabusharma@hotmail.com
Website: www.gloxconsultancy.com
Branch Office :
H. No.- 563/B, Sector - F
Govind Nagar (Near, Mahavidhya Kund / Ratan School)
Mathura, Uttar Pradesh, 281001, India
Mobile:+91 75202-02200 , 91 9528468383
Email: director@gloxconsultancy.com , mukeshbabusharma@hotmail.com
Website: www.gloxconsultancy.com
'''
# print(r"\n") # print \n
# pattern = re.compile(r'com')
# pattern = re.compile(r'^Reg. Office')
# pattern = re.compile(r'com$')
#pattern = re.compile(r'co*')
# pattern = re.compile(r'c*o*')
# pattern = re.compile(r'com' '+')
# pattern = re.compile(r'com ' '{2}') # two blank space after com
# pattern = re.compile(r'(-){1}')
# pattern = re.compile(r'(-){1}|:')
# pattern = re.compile(r'\AReg. Office')
# pattern = re.compile(r'\b.com')
# pattern = re.compile(r'83\b')
# pattern = re.compile(r'\d{5}-\d{5}') # find number like 75202-02200
#pattern = re.compile(r'.(91) \d{10}')
pattern = re.compile(r'([a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+\.[a-zA-Z]+)')
# matches = pattern.finditer(mytext)
# for match in matches:
# print(match.group())
#print(mytext[229:232])
e = re.findall(pattern, mytext)
print(e)