-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregularexpression.py
More file actions
67 lines (65 loc) · 1.82 KB
/
regularexpression.py
File metadata and controls
67 lines (65 loc) · 1.82 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
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
# import re# regular expression
# message="call me 124-696-7587 tomarrow"\
# "or at 346-965-7549"
# X=re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
# mo=X.search(message)
# print(mo.group())
# print(X.findall(message),"findall")
# X=re.compile(r'(\d\d\d)-(\d\d\d)-(\d\d\d\d)')
# mo=X.search(message)
# print(mo.group())
# print(mo.group(1))
# print(mo.group(2))
# print(mo.group(3))
# message="call me (124) 696 7587 tomarrow"
# X=re.compile(r'(\d\d\d) \d\d\d \d\d\d\d')
# mo=X.search(message)
# print(mo.group())
# print(X.findall(message))
#
message=" call me 460-967-3769"\
" or 751-369-4865 "
import re
MobilePhoneX=re.compile(r'(\d\d\d)-(\d\d\d)-(\d\d\d\d)')
y=MobilePhoneX.search(message)
print(y.group())
print(MobilePhoneX.findall(message))
print(y.group(1))
print(y.group(2))
print(y.group(3))
for i in MobilePhoneX.findall(message):
print(y.group())
print("pin with number")
print()
message=" call me (460) 967-3769, or (751) 369-4865 "
MobilePhoneX=re.compile(r'\(\d\d\d\) \d\d\d-\d\d\d\d')
y=MobilePhoneX.search(message)
print(y.group())
print(MobilePhoneX.findall(message))
print("#pipe character")
# batRegX=re.compile(r'Bat(man|mobile|copter|bat)')
# y=batRegX.search("Batman lost a wheel")
# print(y.group())
T=re.compile(r'Bat(man|ball|stamp|cricket)')
s=T.search("i am play Batball")
print(s.group())
print("? 0 or 1 time")
X=re.compile(r'Bat(wo)?man')
z=X.search("Advanture of Batman")
print(z.group())
z=X.search("Advanture of Batwoman")
print(z.group())
print(" * is zero or more ")
X=re.compile(r'Bat(Wo)*man')
# y=X.search("hye Wowoman")
# print(y.group())
# t=X.search("hye man")
# print(t.group())
print("denote start with^ and $ denote with endwith")
txt="the rain is. spain"
x=re.search("^the.*spain$",txt)
print(x.group())
print("wide space")
x=re.search("\s","the rain in spain")
print(x.start())
print("split function")