fork download
  1. import re
  2. pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$'
  3. text = "t'ogfni?fyevdsj@hmi.dev"
  4.  
  5. def repl(x):
  6. return "{}@{}".format(re.sub(r'[^a-zA-Z0-9_.+-]+', '', x.group(1)),
  7. ".".join([re.sub(r'[^a-zA-Z0-9-]+', '', y) for y in x.group(2).split('.')]) )
  8.  
  9. if re.fullmatch(pattern, text):
  10. print("Valid email: {}".format(text))
  11. else:
  12. email = re.sub(r"(.*)@(.*)", repl, text)
  13. print("Filtered email: {}".format(email))
Success #stdin #stdout 0.02s 9388KB
stdin
Standard input is empty
stdout
Filtered email: togfnifyevdsj@hmi.dev