5.2.1
import re
line = "Cats are smarter than dogs"
matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)
if matchObj:
    print "matchObj.group() : ", matchObj.group() print "matchObj.group(1) : ", matchObj.group(1) print "matchObj.group(2) : ", matchObj.group(2)
else:
print "No match!!"

5.2.2
import re

line = "Cats are smarter than dogs";
matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)
if matchObj:
print "matchObj.group() : ", matchObj.group() print "matchObj.group(1) : ", matchObj.group(1) print "matchObj.group(2) : ", matchObj.group(2)
else:
print "No match!!"

5.2.3
import re

phone = "2004-959-559 # This is Phone Number"
num = re.sub(r'#.*$', "", phone) 
print "Phone Num : ", num

num = re.sub(r'\D', "", phone) 
print "Phone Num : ", num
