regular expressions in python simple example the following simple python program illustrates the basic use of the re module it is necessary to import the re module before you can use it import re text 'john williamspattern '[jj]ohnprint('looking in'text 'for the pattern'patternif re search(patterntext )print('match has been found'when this program is runwe get the following outputlooking in john williams for the pattern [jj]ohn match has been found if we look at the codewe can see that the string that we are examining contains 'john williamsand that the pattern used with this string indicates that we are looking for sequence of 'jor 'jfollowed by 'ohnto perform this test we use the re search(function passing the regex patternand the text to testas parameters this function returns either none (which is taken as meaning false by the if statementor match object (which always has boolean value of trueas of course 'johnat the start of text does match the patternthe re search(function returns match object and we see the 'match has been foundmessage is printed out both the match object and search(method will be described in more detail belowhoweverthis short program illustrates the basic operation of regular expression the match object match objects are returned by the search(and match(functions they always have boolean value of true the functions match(and search(return none when there is no match and match object when match is found it is therefore possible to use match object with an if statement