Discuss / Python / 打卡

打卡

Topic source

露心

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

第一题

def is_valid_email(addr):
    #^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
    #^[0-9a-zA-Z\_][0-9a-zA-Z\_\.]{0,10}+\@[0-9a-zA-Z\_]+\.com$之前错误的写法
    if re.match(r'^\w+([+.]\w+)*\@+\w+([+-]\w+)*\.com$', addr):
        return True
    else :
        return False

第二题

def name_of_email(addr):

    m=re.match(r'^\<?([a-zA-Z\s]+)\>?[a-zA-Z\s]*\@[a-zA-Z]+\.[a-zA-Z]+$',addr)
    print(m.group(1))
    return m.group(1)

  • 1

Reply