Articles → Python → Search Function In Python
Search Function In Python
Purpose
Example
import re
pattern = "country"
text = "my country is India"
#returns Match object
match = re.search(pattern, text)
print(match)
Output
Finding Multiple Instances
import re
pattern = "country"
text = "my country is India and I belong to this country"
for match in re.finditer(pattern, text):
print(match.span())
Output