-
Notifications
You must be signed in to change notification settings - Fork 0
/
regexp.py
65 lines (55 loc) · 1.4 KB
/
regexp.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
import re
'''#str='abaabcd;aaa444efpqabefc999daaaa'
str='English-45; Maths-90; Science-80'
#print(str)
#pat='a{2,4}'
#pat='abc?'
pat='\W'
res=re.findall(pat,str)
print(res)
str='MVM COLLEGE OF COMMERCE MANAGEMENT & IT'
#pat='COL|COM'
#pat='COL[A-Z]{4}|COM'
#pat='CO[LM][A-Z]{4,5}'
pat='IT\Z'
#pat='OL{2}|OM{2}'
#pat='O[LM]'
res=re.findall(pat,str)
print(res)
'''
str='Sachin has a good bat.\nSachin is a good batsman. ' \
'\nX has a good bat.'
print(str)
#pat='\ASachin'
#pat='\Bhin'
#pat='hin\b'
#pat='bat|bit'
#res=re.findall(pat,str)
res=re.findall(r'hin\b',str,re.M)
print(res)
str='MVM COLLEGE OF COMMERCE MANAGEMENT & IT'
res=re.search('o.', str,re.I)
print('Search Result : ', res)
str='MVM COLLEGE OF COMMERCE MANAGEMENT & IT'
res=re.match('.*college', str,re.I)
print('Match Result : ', res)
print('Match Result : ', res.group(0))
str='MVM COLLEGE OF COMMERCE MANAGEMENT & IT'
res=re.findall('O.', str,re.I)
print('Findall Result : ', res)
str='(2825)-245902'
pat='(\(\d{4}\))\-(\d{6})'
res=re.match(pat,str)
if re.match(pat,str):
print('Number matches')
print('group 1', res.group(1))
print('group 1', res.group(2))
else:
print('No Match')
str='Sachin has a good bat.\nSachin is a good batsman. ' \
'\nX has a good bat.'
print(str)
res=re.findall(r'hin\b',str,re.M)
print(res)
res=re.findall(r'\bgoo',str,re.M)
print(res)