regex or pattern python code example
Example 1: Using the Python string below to perform a search using a regular expression that you create. search_string=’’’This is a string to search for a regular expression like regular expression or regular-expression or regular:expression or regular&expression’’’
match1 = re.findall(pattern, search_string)
if match1 != None:
print(pattern + 'matched')
else:
print(pattern + 'did not match')
Example 2: python regular expression
import re
test_string = 'Hello greppers!'
pattern = re.compile(r'Hello')
match = pattern.finditer(test_string)
for match in matches:
print(match)