Discuss / Python / 测试成功

测试成功

Topic source

筱枫_Edward

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

版本1:

def is_valid_email(addr):

if re.match(r'^([0-9a-zA-Z\_\.]+)\@([0-9a-zA-Z]+)\.(\w{2,3})$', addr):
    return True

else:
    return False

版本2:

def name_of_email(addr):

if addr[0] == "<":
    m = re.match(r'^\<([0-9a-zA-Z\_\s]+)*', addr)
    return m.group(1)

else:
    m = re.match(r'^([0-9a-zA-Z\_\.]+)*', addr)
    return m.group(1)

return None

筱枫_Edward

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

版本2:

def name_of_email(addr):

return list(filter(None, re.split(r'[\<\>\@]+', addr)))[0]

  • 1

Reply