import re m = re.match('foo', 'foo') # pattern matches string if m is not None: # show match if successful m.group()