Skip to content

Instantly share code, notes, and snippets.

@ViBiOh
Last active April 29, 2016 15:13
Show Gist options
  • Save ViBiOh/07a954f5ff2ac4bc72c4 to your computer and use it in GitHub Desktop.
Save ViBiOh/07a954f5ff2ac4bc72c4 to your computer and use it in GitHub Desktop.
Clean a Gmail address to its real identifier
email.trim().replace(/^(.*?)(?:\+.*?)?(@gmail\.com)$/gi, '$1$2').replace(/\.(?!com$)/g, '');
@ViBiOh
Copy link
Author

ViBiOh commented Apr 29, 2016

In its address, Gmail ignores dots and everything after the first plus sign. Mails sent to the "valid" address and those "disguised" will all go into the Inbox. Google allows you to generate personal addresses. This script removes everything superfluous to identify the unique address.

const email = 'jo.nh.doe+spam.randomwebsite+crappy@gmail.com';
email.trim().replace(/^(.*?)(?:\+.*?)?(@gmail\.com)$/gi, '$1$2').replace(/\.(?!com$)/g, '');
<- jonhdoe@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment