-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basics.py
36 lines (24 loc) · 900 Bytes
/
Basics.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
import re
# string
stringData = "Data is easy to get."
#syntax
# re.search(pattern,string,flags)
# re.match(pattern,string,flags)
''' search a from given string
search is used to search the data from anywhere in the sentence
span(1,2) is the index of the occurrence of the words i.e. 'a' is occurred at index 1 and end at index at 2'''
print(re.search('a', stringData))
# group() is used to get the text
print()
print(re.search('Data', stringData).group())
# or
print(re.search('is', stringData).group(0))
# above statements are same
# match is used to find the first character from the sentence
print(re.match('D',stringData).group(0))
# produce None because t is not found at first character
print(re.match('t',stringData))
# start() is used to print first index
print(re.search('s',stringData).start())
# end() is used to print end index
print(re.search('s',stringData).end())