Discuss / Python / 正则表达式

正则表达式

Topic source

YOUTH

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

第一题:

def is_valid_email(addr):

    if re.match(r'^[a-zA-Z.]+@[a-z]+.com$',addr):

        return True

    else:

        return False

第二题:

def name_of_email(addr):

    if re.match(r'^<([a-zA-Z ]+)> [a-zA-Z]+@[a-zA-Z]+.org$',addr):

        r1=re.match(r'^<([a-zA-Z ]+)> [a-zA-Z]+@[a-zA-Z]+.org$',addr).group(1)

        return r1

    elif re.match(r'([a-zA-Z]+)@[a-zA-Z]+.org$',addr):

        return re.match(r'([a-zA-Z]+)@[a-zA-Z]+.org$',addr).group(1)

    return None


  • 1

Reply