Last active
August 20, 2024 17:52
-
-
Save ncalm/70ffe415819b2a678fe4ad1c32da06bf to your computer and use it in GitHub Desktop.
This Excel LAMBDA function builds a regex pattern of variants of the local part of an email address when given a Full Name
This file contains 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
/* Takes a name in First Last format and produces a regex string | |
of variants of that name that might be found before the @ in an email | |
address. | |
Optional parameters can be set to FALSE to exclude specific variants | |
*/ | |
EMAILVARIANTS = LAMBDA( | |
name, [firstlast], [finitlast], [firstlinit], | |
[firstdotlast], [finitdotlast], [firstunderlast], | |
LET( | |
full, LOWER(name), | |
first, TEXTBEFORE(full, " "), | |
last, TEXTAFTER(full, " "), | |
finit, LEFT(first, 1), | |
linit, LEFT(last, 1), | |
f, LAMBDA(bool, pat, IF(OR(ISOMITTED(bool),bool),pat,"")), | |
variants, VSTACK( | |
f(firstlast, first & last), | |
f(finitlast, finit & last), | |
f(firstlinit, first & linit), | |
f(firstdotlast, first & "\." & last), | |
f(finitdotlast, finit & "\." & last), | |
f(firstunderlast, first & "_" & last) | |
), | |
result, TEXTJOIN("|", , variants & "@.*"), | |
MID(result,2,LEN(result)) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment