In actual programs, the most common style is to store the match object in a variable, and then check if it was$_{None}$ . This usually looks like: p =re.compile(...) m =p.match('string goes here') if m: print('Match found:', m.group()) else : print('No match') >>> p =re.compile( r'\d+') >>> p.findall( '12 drummers drumming, 11 pipers piping, 10 lords a-leaping ') ['12', '11', '10'] Two pattern methods return all of the matches for a pattern. findall() returns a list of matching strings: The$_{r}$ prefix, making the literal a raw string literal, is needed in this example because escape sequences in a nor- mal “cooked” string literal that are not recognized by Python, as opposed to regular expressions, now result in a DeprecationWarning and will eventually become a SyntaxError . See The Backslash Plague . findall() has to create the entire list before it can be returned as the result. The finditer() method returns a sequence of match object instances as an iterator: >>> iterator =p.finditer('12 drummers drumming, 11 ... 10 ... ') >>> iterator <callable_iterator object at 0x...> >>>for match in iterator: ... print(match.span()) ... (0, 2) (22, 24) (29, 31) 3.4 Module-Level Functions You don’t have to create a pattern object and call its methods; the$_{re}$ module also provides top-level functions called match() , search() , findall() , sub() , and so forth. These functions take the same arguments as the corresponding pattern method with the RE string added as the first argument, and still return either$_{None}$ or a match object instance. >>> print(re.match(r'From\s+','Fromage amk')) None >>> re.match(r'From\s+','From amk Thu May 14 19:12:10 1998 ') <re.Match object; span=(0, 5), match='From '> Under the hood, these functions simply create a pattern object for you and call the appropriate method on it. They also store the compiled object in a cache, so future calls using the same RE won’t need to parse the pattern again and again. Should you use these module-level functions, or should you get the pattern and call its methods yourself? If you’re accessing a regex within a loop, pre-compiling it will save a few function calls. Outside of loops, there’s not much difference thanks to the internal cache. 7