Google News
logo
Python Program to Using the search() function
In the following example of Python program that uses the `search()` function in Python's `re` module to search a string for a pattern :
Program :
import re

string = "The quick brown fox jumps over the lazy dog in Spain."
pattern = "fox"

match = re.search(pattern, string)

if match:
    print("Found a match!")
else:
    print("No match found.")
Output :
Found a match!
This program will search the string "The quick brown fox jumps over the lazy dog in Spain." for the pattern "fox". If the pattern is found, it will print "Found a match!". If the pattern is not found, it will print "No match found.".

You can change the value of the `pattern` variable to search for different patterns in the string.