-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctioninreModule1.py
26 lines (24 loc) · 1.05 KB
/
FunctioninreModule1.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
#Important Function in re module
''' match() = returns the matched Pattern if the beginning of pattern matched or else None.
fullmatch()=returns the fullmatch pattern if the complete pattern is matched or else None.
search()=returns the first occurrence of pattern if found else returns None.
findall()=returns the list all ocurrences of pattern if found.
'''
import re
m=re.match('abc','abcdefghituyi')
if m!=None:
print("matched the beginning,starting index:{},end={},pattern={}".format(m.start(),m.end(),m.group()))
else:
print("Match pattern is not available..")
m=re.fullmatch('abcdefghituyi','abcdefghituyi')
if m!=None:
print("fullmatched the pattern,starting index:{},end={},pattern={}".format(m.start(),m.end(),m.group()))
else:
print("FullMatch pattern is not available..")
m=re.search('def','abcdefghituyi')
if m!=None:
print("searching pattern found,starting index:{},end={},pattern={}".format(m.start(),m.end(),m.group()))
else:
print("Searched pattern is not available..")
l=re.findall('abc','abcdefgabchituyi')
print("list of all occurrences:",l)