re-interactive txt for all the interactive code run in this section)text 'hello spam worldtext 'hello spam otherthe match performed in the following code does not precompileit executes an immediate match to look for all the characters between the words hello and world in our text stringsimport re matchobj re match('hello*)world'text print(matchobjnone when match fails as it does here (the text string doesn' end in world)we get back the none objectwhich is boolean false if tested in an if statement in the pattern string we're using here in the first argument to re matchthe words hello and world match themselvesand *means any character repeated zero or more times (*the fact that it is enclosed in parentheses tells python to save away the part of the string matched by that part of the pattern as group-- matched substring available after the match to see howwe need to make match workmatchobj re match('hello*)world'text print(matchobjmatchobj group( spam when match succeedswe get back match objectwhich has interfaces for extracting matched substrings--the group( call returns the portion of the string matched by the firstleftmostparenthesized portion of the pattern (our *)as mentionedmatching is not just yes/no answerby enclosing parts of the pattern in parenthesesit is also way to extract matched substrings in this casewe've parsed out the text between hello and world group number is the entire string matched by the pattern--useful if you want to be sure your pattern is consuming all the text you think it is the interface for precompiling is similarbut the pattern is implied in the pattern object we get back from the compile callpattobj re compile('hello*)world'matchobj pattobj match(text matchobj group( spam againyou should precompile for speed if you will run the pattern multiple timesand you normally will when scanning files line by line here' something bit more complex that hints at the generality of patterns this one allows for zero or more blanks or tabs at the front (\ ]*)skips one or more after the word hello (\ ]+)captures characters regular expression pattern matching