def name_of_email(addr):
m = re.match(r'([<]*)([A-Za-z0-9_.\s]*)([>]*)\s*([a-z]*)@([0-9a-z]+).org',addr)
if m != None:
if m.group(1) != None:
print(m.group(2))
else:
print(m.group(4))
return True
else:
return False
print(name_of_email('< Tom Paris > tom@voyager.org'))
print(name_of_email('tom@voyager.org'))
孟祥森丶
第一题:
def is_valid_email(addr): if re.match(r'([a-z0-9_.]*)@([0-9a-z]+).com',addr): return True else: return False
print(is_valid_email('someone@gmail.com')) print(is_valid_email('bill.gates@microsoft.com')) print(is_valid_email('bob#example.com')) print(is_valid_email('mr-bob@example.com'))
第二题:
def name_of_email(addr): m = re.match(r'([<]*)([A-Za-z0-9_.\s]*)([>]*)\s*([a-z]*)@([0-9a-z]+).org',addr) if m != None: if m.group(1) != None: print(m.group(2)) else: print(m.group(4)) return True else: return False print(name_of_email('< Tom Paris > tom@voyager.org')) print(name_of_email('tom@voyager.org'))