Mega Code Archive

 
Categories / Python Tutorial / Regular Expressions
 

Here is an example of a failed match where None is returned

import re m = re.match('foo', 'bar')# pattern does not match string if m is not None: m.group()# (1-line version of ifclause) m = re.match('foo', 'food on the table') # match succeeds print m.group() print re.match('foo', 'food on the table').group()