-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegular_expression.py
92 lines (73 loc) · 1.58 KB
/
Regular_expression.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
# import re
#1. match
#2. search
#3. findall
#4. find & replace
# pat=r"arun"
#------match-----------
# if re.match(pat,'arun sathyan, how are you doing'):
# print('present')
# else:
# print('absent')
#--------search----------
# if re.search(pat,'hello arun sathyan'):
# print('present')
# else:
# print('absent')
#---------findall---------------
# print(re.findall(pat,'arun sathyan hello arun where are you arun'))
#------find&replace-------------
# strg="I'm arun Sathyan, I'm an amazonian"
# new=re.sub('arun','Arun',strg) # first element is the pattern 'arun' & second one is the replacement'Arun'
# print(new)
#---------.match------------------
# pat=r'a..n'
#
# if re.match(pat,'arun'):
# print('present')
# else:
# print('absent')
#--------------character class----------------------
# pat=r'[A-Z][0-9][a-z]'
#
# if re.search(pat,'B8i'):
# print('preset')
# else:
# print('absent')
#---------------------------------------------------------
# import re
#
# s=r'arun'
#
# str1='arun sathyan and arun good and arun bad'
#
# if re.match(s,str1):
# print('present')
# else:
# print('absent')
#
# print('----------------------------')
#
# if re.search(s,str1):
# print('present')
# else:
# print('absent')
#
# print('----------------------------')
#
# print(re.findall(s,str1))
#
# print('----------------------------')
#
# str2=re.sub(s,'Arun',str1)
#
# print(str2)
#
# print('----------------------------')
#
# if re.match('ar.n','aroun sathyan'):
# print('present')
# else:
# print('absent')
#
# print('----------------------------')