fork(2) 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. def repl(x):
  5. return "{}@{}.{}".format(re.sub(r'[^a-zA-Z0-9_.+-]+', '', x.group(1)),
  6. re.sub(r'[^a-zA-Z0-9.-]+', '', x.group(2)),
  7. re.sub(r'[^a-zA-Z0-9.-]+', '', x.group(3)))
  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.03s 9464KB
stdin
Standard input is empty
stdout
Filtered email: togfnifyevdsj@hmi.dev