Discuss / Python / 交作业

交作业

Topic source

倾情守望

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

练习1

def is_valid_email(addr):
    pattern = r'^[\w\.]+\@[\w]+\.\w{2,}$'    
    m = re.compile(pattern)
    return m.match(addr)

练习2

def name_of_email(addr):
    pattern = r'^\<?([\w\s]+)[\>\@]'    
    m = re.compile(pattern)
    g = m.match(addr)
    if g:
        return g.group(1)
    return ''

  • 1

Reply