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)),
".".join([re.sub(r'[^a-zA-Z0-9-]+', '', y) for y in x.group(2).split('.')]) )
if re.fullmatch(pattern, text):
print("Valid email: {}".format(text))
else:
email = re.sub(r"(.*)@(.*)", repl, text)
print("Filtered email: {}".format(email))
aW1wb3J0IHJlCnBhdHRlcm4gPSByJ15bYS16QS1aMC05Xy4rLV0rQFthLXpBLVowLTktXSsoPzpcLlthLXpBLVowLTktXSspKyQnCnRleHQgPSAidCdvZ2ZuaT9meWV2ZHNqQGhtaS5kZXYiCgpkZWYgcmVwbCh4KToKCXJldHVybiAie31Ae30iLmZvcm1hdChyZS5zdWIocidbXmEtekEtWjAtOV8uKy1dKycsICcnLCB4Lmdyb3VwKDEpKSwKCQkiLiIuam9pbihbcmUuc3ViKHInW15hLXpBLVowLTktXSsnLCAnJywgeSkgZm9yIHkgaW4geC5ncm91cCgyKS5zcGxpdCgnLicpXSkgKQoKaWYgcmUuZnVsbG1hdGNoKHBhdHRlcm4sIHRleHQpOgoJcHJpbnQoIlZhbGlkIGVtYWlsOiB7fSIuZm9ybWF0KHRleHQpKQplbHNlOgoJZW1haWwgPSByZS5zdWIociIoLiopQCguKikiLCByZXBsLCB0ZXh0KQoJcHJpbnQoIkZpbHRlcmVkIGVtYWlsOiB7fSIuZm9ybWF0KGVtYWlsKSk=