import re
pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$'
text = "t'ogfni?fyevdsj@hmi.dev"
def repl(x):
return "{}@{}.{}".format(re.sub(r'[^a-zA-Z0-9_.+-]+', '', x.group(1)),
re.sub(r'[^a-zA-Z0-9.-]+', '', x.group(2)),
re.sub(r'[^a-zA-Z0-9.-]+', '', x.group(3)))
if re.fullmatch(pattern, text):
print("Valid email: {}".format(text))
else:
email = re.sub(r"(.*)@(.*)\.(.*)", repl, text)
print("Filtered email: {}".format(email))
aW1wb3J0IHJlCnBhdHRlcm4gPSByJ15bYS16QS1aMC05Xy4rLV0rQFthLXpBLVowLTktXSsoPzpcLlthLXpBLVowLTktXSspKyQnCnRleHQgPSAidCdvZ2ZuaT9meWV2ZHNqQGhtaS5kZXYiCmRlZiByZXBsKHgpOgoJcmV0dXJuICJ7fUB7fS57fSIuZm9ybWF0KHJlLnN1YihyJ1teYS16QS1aMC05Xy4rLV0rJywgJycsIHguZ3JvdXAoMSkpLAoJCXJlLnN1YihyJ1teYS16QS1aMC05Li1dKycsICcnLCB4Lmdyb3VwKDIpKSwKCQlyZS5zdWIocidbXmEtekEtWjAtOS4tXSsnLCAnJywgeC5ncm91cCgzKSkpCgppZiByZS5mdWxsbWF0Y2gocGF0dGVybiwgdGV4dCk6CglwcmludCgiVmFsaWQgZW1haWw6IHt9Ii5mb3JtYXQodGV4dCkpCmVsc2U6CgllbWFpbCA9IHJlLnN1YihyIiguKilAKC4qKVwuKC4qKSIsIHJlcGwsIHRleHQpCglwcmludCgiRmlsdGVyZWQgZW1haWw6IHt9Ii5mb3JtYXQoZW1haWwpKQ==