-
Notifications
You must be signed in to change notification settings - Fork 0
/
findall.py
55 lines (45 loc) · 862 Bytes
/
findall.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
import re
txt = "The rain in spain"
x = re.findall("ai", txt)
print(x)
print()
x = re.findall("India", txt)
print(x)
print()
if (x):
print("There is atleast one match")
else:
print("No match")
print()
#search function
import re
txt = "the rain in spain"
x = re.search("\s", txt)
print("the first white space character is located in position:", x.start())
print()
import re
txt = "The rain in Spain"
x = re.search("Portugal", txt)
print(x)
print()
#split function
import re
txt = "the rain in spain"
x = re.split("\s", txt)
print(x)
print()
import re
txt = "the rain in spain"
x = re.split("\s", txt, 2)
print(x)
print()
#sub function
import re
txt = "the rain in spain"
x = re.sub("\s", "9", txt)
print(x)
print()
import re
txt = "the rain in spain"
x = re.sub("\s", "9", txt, 2)
print(x)