Discuss / Python / 作业

作业

Topic source

ghghgh147258

#1 Created at ... [Delete] [Delete and Lock User]

1 import re

def is_valid_email(addr): if re.match(r'^(\w+.?\w+\@\w+.com)$',addr): return True

assert is_valid_email('someone@gmail.com') assert is_valid_email('bill.gates@microsoft.com') assert not is_valid_email('bob#example.com') assert not is_valid_email('mr-bob@example.com') print('ok')

2

import re

def name_of_email(addr): m=re.match(r'^<?(\w+\s?\w+)>?\s?\w*\@\w+.org$',addr) return m.group(1)

assert name_of_email('<Tom Paris> tom@voyager.org') == 'Tom Paris' assert name_of_email('tom@voyager.org') == 'tom' print('ok')


  • 1

Reply