Python组合数据

用户输入的邮箱地址字符串,其中可以有英文大小写字母、数字、@和.这4种字符,且头尾可能有空格,假设输入没有问题。
检验这个字符串是否符合邮箱的格式:

如果合法,则输出邮箱的全小写标准形式,否则输出"不合法"

例如:
输入"ShenZhen@QQ.com",输出:shenzhen@qq.com
输入" Shen.Zhen2022@qq.com",输出:shen.zhen2022@qq.com
输入"shenzhen@qq",输出:不合法
输入"shen.zhen@.com",输出:不合法
输入"shenzhen.@qq.com", 输出:不合法


import re
regex = re.compile(r'([A-Za-z0-9]+[.-_ ])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')

def isValid(email):
    if re.fullmatch(regex, email.strip()):
        print(email.strip().lower())
    else:
      print("无效的email地址")

while 1:
    email = input('输入邮箱:')
    isValid(email)
这篇文章:Python组合数据 也许有你想要的答案,你可以看看