import repatt = '\w+@(\w+\.)?\w+\.com're.match(patt, 'nobody@xxx.com').group()re.match(patt, 'nobody@www.xxx.com').group()patt = '\w+@(\w+\.)*\w+\.com're.match(patt, 'nobody@www.xxx.yyy.zzz.com').group()