将无效的电子邮件格式替换为有效的电子邮件格式

问题描述 投票:0回答:1

在Power Query中,我有一个包含无效电子邮件的电子邮件列表。我正在寻找使用M代码来识别和“修复”它们。例如,我的电子邮件列表中应包含“ [email protected]

我正在寻找Power Query以查找相似的电子邮件地址,然后生成有效电子邮件的输出。对于上面的示例,它应该是“ [email protected]

本质上,我想执行以下操作:

  • 删除前面的数字(数字位数有所不同)
  • 删除“ @ error.invalid.com”
  • 将第一个下划线“ _”从右侧替换为“。”
  • 将第二个下划线“ _”从右侧替换为“ @”

我还是Power Query的新手,尤其是M代码。感谢您能获得的任何帮助和指导。

if-statement replace powerquery
1个回答
0
投票
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表达式的逻辑将需要改进)。
  • © www.soinside.com 2019 - 2024. All rights reserved.