Skip to content

Instantly share code, notes, and snippets.

@am-on
Created November 17, 2021 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save am-on/d2af2cf3c655b69c40fdd5de5cd1f517 to your computer and use it in GitHub Desktop.
Save am-on/d2af2cf3c655b69c40fdd5de5cd1f517 to your computer and use it in GitHub Desktop.
Normalize gmail email
def normalize_gmail(email: str) -> str:
"""Normalize Gmail address.
foo@gmail.com
f.oo@gmail.com
fo.o+bar@gmail.com
All above addresses belongs to the same gmail account.
Convert all above cases to address with no `.` and `+` : foo@gmail.com
"""
username = email.lower().split("@")[0]
username = username.replace(".", "")
if "+" in username:
username = username.split("+")[0]
return f"{username}@gmail.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment