find with regex 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: searching for a pattern in text with re python
import re
xx = "guru99,education is fun"
r1 = re.findall(r"^\w+",xx)
print(r1)
Example 3: python .findall
match = re.search(r'bb', 'aabbcc')
match = re.search(r'cd', 'aabbcc')
match = re.search(r'...c', 'aabbcc')
match = re.search(r'\d\d\d', 'p123g')
match = re.search(r'\w\w\w', '@@abcd!!')
Example 4: regex in python
import re
sample = "Nothing lasts... but nothing is lost"
found = re.findall("thing", sample)
print(found)