all the regex functions in python are in the re module enter the following into the interactive shell to import this moduleimport re note most of the examples in this will require the re moduleso remember to import it at the beginning of any script you write or any time you restart mu otherwiseyou'll get nameerrorname 'reis not defined error message passing string value representing your regular expression to re compile(returns regex pattern object (or simplya regex objectto create regex object that matches the phone number patternenter the following into the interactive shell (remember that \ means " digit characterand \ \ \ -\ \ \ -\ \ \ \ is the regular expression for phone number pattern phonenumregex re compile( '\ \ \ -\ \ \ -\ \ \ \ 'now the phonenumregex variable contains regex object matching regex objects regex object' search(method searches the string it is passed for any matches to the regex the search(method will return none if the regex pattern is not found in the string if the pattern is foundthe search(method returns match objectwhich have group(method that will return the actual matched text from the searched string ( 'll explain groups shortly for exampleenter the following into the interactive shellphonenumregex re compile( '\ \ \ -\ \ \ -\ \ \ \ 'mo phonenumregex search('my number is 'print('phone number foundmo group()phone number foundthe mo variable name is just generic name to use for match objects this example might seem complicated at firstbut it is much shorter than the earlier isphonenumber py program and does the same thing herewe pass our desired pattern to re compile(and store the resulting regex object in phonenumregex then we call search(on phonenumregex and pass search(the string we want to match for during the search the result of the search gets stored in the variable mo in this examplewe know that our pattern will be found in the stringso we know that match object will be returned knowing that mo contains match object and not the null value nonewe can call group(on mo to return the match writing mo group(inside our print(function call displays the whole matchpattern matching with regular expressions