Discuss / Python / 交作业

交作业

Topic source

第二题

def name_of_email(addr):
    re_email = re.compile(r'^<?(\w*\s*\w*)>?\s*?(\w*)?@\w+\.\w+$')
    if re_email.match(addr):
        return re_email.match(addr).groups(1)[0]
    else:
        return None
    

如果使用r'^<?([\w\s]+)>?\s?(\w+)@\w+\.\w+$'

输出为'to'

☜樂☞

#2 Created at ... [Delete] [Delete and Lock User]
(\w*)? 可以直接\w*

  • 1

Reply