Discuss / Python / 作业

作业

Topic source

s凡s

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

作业1:

def is_valid_email(addr):
    return re.match(r'^[\w\d]+[\w\d\.]*@([\w\d]+\.)+[\w\d]+$', addr)

作业2:

def name_of_email(addr):
    m = re.match(r'^(<([\w\d\s]+)>[\s]+)?([\w\d]+[\w\d\.]*)@([\w\d]+\.)+[\w\d]+$', addr)
    if m:
        if m.group(1):
            return m.group(2)
        else:
            return m.group(3)
    else:
        return None

  • 1

Reply