Created
May 5, 2020 22:25
-
-
Save sklinkert/15c7f46c6039601b4eece9ff508c378a to your computer and use it in GitHub Desktop.
Guess firstname and lastname from mail address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// guessNameFromMail - Examples: | |
// [email protected] -> Warren Buffett | |
// [email protected] -> Warren Buffett | |
// [email protected] -> Warren Buffett | |
// [email protected] -> W. Buffett | |
func guessNameFromMail(mail string) (firstname, lastname string) { | |
re := regexp.MustCompile(`^([A-Za-z]+)[\-\.\_]([A-Za-z]+)[0-9]*@`) | |
matches := re.FindAllStringSubmatch(mail, -1) | |
if len(matches) == 1 && len(matches[0]) == 3 { | |
firstname := strings.Title(matches[0][1]) | |
lastname := strings.Title(matches[0][2]) | |
if len(firstname) == 1 { | |
firstname = firstname + "." | |
} | |
return firstname, lastname | |
} | |
return "", "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment