1import re
2
3# The string you want to find a pattern within
4test_string = 'Hello greppers!'
5
6# Creating a regular expression pattern
7# This is a simple one which finds "Hello"
8pattern = re.compile(r'Hello')
9
10# This locates and returns all the occurences of the pattern
11# within the test_string
12match = pattern.finditer(test_string)
13
14# Outputs all the ocurrences which were returned as
15# as match objects
16for match in matches:
17 print(match)
18
19
1import re
2pattern = re.compile('[a-zA-Z ]+') # a...z A...Z and space allowed
3message = "Weather is nice"
4if pattern.match(message).group() == message:
5 print("match")
6else:
7 print("no match")
1import re
2
3pattern = '^a...s$'
4test_string = 'abyss'
5result = re.match(pattern, test_string)
6
7if result:
8 print("Search successful.")
9else:
10 print("Search unsuccessful.")
11