在Power Query中,我有一个包含无效电子邮件的电子邮件列表。我正在寻找使用M代码来识别和“修复”它们。例如,我的电子邮件列表中应包含“ [email protected]”
我正在寻找Power Query以查找相似的电子邮件地址,然后生成有效电子邮件的输出。对于上面的示例,它应该是“ [email protected]”
本质上,我想执行以下操作:
我还是Power Query的新手,尤其是M代码。感谢您能获得的任何帮助和指导。
let
cleanEmailAddress = (invalidEmailAddress as text) as text =>
let
removeLeadingNumbers = Text.AfterDelimiter(invalidEmailAddress, "."), // Assumes invalid numbers are followed by "." which itself also needs removing.
removeInvalidDomain = Text.BeforeDelimiter(removeLeadingNumbers, "@"),
replaceLastOccurrence = (someText as text, oldText as text, newText as text) as text =>
let
lastPosition = Text.PositionOf(someText, oldText, Occurrence.Last),
replaced = if lastPosition >= 0 then Text.ReplaceRange(someText, lastPosition, Text.Length(oldText), newText) else someText
in replaced,
overwriteTopLevelDomainSeparator = replaceLastOccurrence(removeInvalidDomain, "_", "."),
overwriteAtSymbol = replaceLastOccurrence(overwriteTopLevelDomainSeparator, "_", "@")
in overwriteAtSymbol,
cleaned = cleanEmailAddress("[email protected]")
in
cleaned
关于:
“删除前面的数字(数字位数有所不同)”
.
(如果删除前导数字则保留),但是您的预期输出("[email protected]"
)建议将其删除。在前导数字后立即没有.
的电子邮件地址将返回错误(并且removeLeadingNumbers
表达式的逻辑将需要改进)。