-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegular.py
99 lines (54 loc) · 1.33 KB
/
Regular.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
#!/usr/bin/env python3
# -*- coding utf-8 -*-
__Author__ ='eamon'
'Regular Expression!'
import re
test= 'user input'
if re.match(r'regular pattern',test):
print('OK')
else:
print('Failed')
r='a b c'.split(' ')
print(r)
r=re.split(r'\s+','a b c')
print(r)
r=re.split(r'[\s;,]+','a, ,;;b;, c')
print(r)
r=re.match(r'^(\d{3})-(\d{3,8})$','010-123456')
print(r.group(0))
#MATCH TIME
t='17:56:30'
m=re.match(r'^(0[0-9]|1[0-9]|2[0-3]|[0-9])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]|[0-9])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]|[0-9])$',t)
r=m.groups()
print(r)
# MATCH DATA
t='^(0[1-9]|1[0-2]|[0-9])-(0[1-9]|1[0-9]|2[0-9]|3[0-1]|[0-9])$'
r=re.match(t,'12-03')
print(r)
# layz mode
r=re.match(r'^(\d+)(0*)$','1023000').groups()
print(r)
r=re.match(r'^(\d+?)(0*)$','1023000').groups()
print(r)
re_tel=re.compile('^(\d{3})-(\d{3,8})$')
r=re_tel.match('021-123456').groups()
print(r)
emailregex='^\w(\w?[\.\-\_]?){1,5}@gmail.com$'
re_telgmal=re.compile(emailregex)
mail='[email protected]'
r=re_telgmal.match(mail)
print(r)
print(r.groups())
if r:
print("OK")
else:
print('not OK')
emailregexwithname='^(<\w+\s\w+>)\s+\w+(?:[.-_]\w+)[email protected]$'
re_telgmal=re.compile(emailregexwithname)
mail='<tony wen> [email protected]'
r=re_telgmal.match(mail)
print(r)
if r:
print("OK")
else:
print('not OK')