txt "the rain in spainx re sub("\ "" "txt print(xoutputthe rain inspain using match function re match(function of re in python will search the regular expression pattern and return the first occurrence the python regex match method checks for match only at the beginning of the string soif match is found in the first lineit returns the match object but if match is found in some other linethe python regex match function returns null example do search that will return match objectimport re txt "the rain in spainx re search("ai"txtprint( #this will print an object outputthe match object has properties and methods used to retrieve information about the searchand the resultspan(returns tuple containing the start-and end positions of the match string returns the string passed into the function group(returns the part of the string where there was match exampleprint the string passed into the functionimport re txt "the rain in spainx re search( "\bs\ +"txt