Discuss / Python / 作业

作业

Topic source

Nghg

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

import re

reEmail = re.compile(r'^[\w\.\s<>]+@[\w\.\s<>]+$')

print(reEmail.pattern)

def is_valid_email(addr):

    return reEmail.match(addr)

reEmail1 = re.compile(r'^([\w\.\s<>]+)@[\w\.\s<>]+$')

reEmail2 = re.compile(r'<?([\w\.\s]+)>?')

def name_of_email(addr):

    match = reEmail1.match(addr)

    if match:

        res = reEmail2.match(match.group(1)).group(1)

        # print('res' + res)

        return res

    return None


  • 1

Reply