-
Notifications
You must be signed in to change notification settings - Fork 179
/
regular_exp.py
32 lines (24 loc) · 860 Bytes
/
regular_exp.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
import re
string = "this is a really cool string really!"
a = re.search('really',string)
print(a)
# the below 4 commands will give error if the searching string does not exist.
print(a.span())
print(a.start())
print(a.end())
print(a.group())
pattern = re.compile('really')
b = pattern.search(string)
c = pattern.findall(string)
pattern = re.compile('this is a really cool string really!')
d = pattern.fullmatch('this is a really cool string really!')
e = pattern.fullmatch('hello this is a really cool string really!') # this should be exact match, otherwise returns none
pattern = re.compile('really')
f = pattern.match('really cool feature') # it starts matching from the first character otherwise returns none
g = pattern.match('yo really')
print(f"b: {b}")
print(f"c: {c}")
print(f"d: {d}")
print(f"e: {e}")
print(f"f: {f}")
print(f"g: {g}")