- search() is a python regex function that searches the string for a match, and returns a Match object if there is a match.
Syntax-
re.search(pattern,string)
-Here pattern is everything that you want to search in the string, metacharacters are also used in making pattern.
Example-
string is s="This is online"
then re.search("is",s)
it will search the 'is' in the given string and match will be found successfully.
program-
import re
#Check if the string starts with "This" and ends with "string":
s= "This is the amazing string"
x = re.search("^This.*string$", s)
if (x):
print("We have a match!")
else:
print("No match")
s= "The amazing string"
x = re.search("^This.*string$", s)
if (x):
print("We have a match!")
else:
print("No match")
We have a match!
No match