我有包含电子邮件附件和隐藏的电子邮件附件的行,例如,使用[at]而不是@。我想把这份清单从所有不是电子邮件的东西中清除。
TLDs是.com、.us和.me。
样本输入
johndoe@example.com
johndoe @example.us
contant johndoe @ example . me
my email is johndoe@example.com
johndoe@example.com is my email
this johndoe @ example.com is my mail
johndoe[at]example.com
my email is johndoe [at] example.com
johndoe[at-sign]example.com
johndoe at example.com
johndoe[at-sign]example[dot]com is my mail
Lorem ipsum dolor sit amet, consectetur adipisicing elit, johndoe[at-sign]example[dot]us
johndoe[at-sign]example[dot]me labore et dolore magna aliqua
Sed do eiusmod tempor incididunt johndoe at example dot com
Duis aute irure dolor in reprehenderit in voluptate JOHNDOE at EXAMPLE dot US aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum johndoe at example dot me我正在使用Notepad++搜索和替换,我的尝试是这个[\w]+(|\s)(@|at|\[at\]|\[at-sign\])(|\s)[\w]+(|\s)(\.|dot)(|\s)(com|us|me),它似乎适用于所有的东西,但不适用于第11、12、13和15行。
这是我自己写的,这是正确的吗?
期望产出:
johndoe@example.com
johndoe@example.us
johndoe @ example . me
johndoe@example.com
johndoe@example.com
johndoe@example.com
johndoe[at]example.com
johndoe [at] example.com
johndoe[at-sign]example.com
johndoe [at-sign] example.com
johndoe[at-sign]example[dot]com
johndoe[at-sign]example[dot]us
johndoe[at-sign]example[dot]me
johndoe at example dot com
JOHNDOE at EXAMPLE dot US
johndoe at exampledotme我不认为这是100%的防弹,因为我读过那个电子邮件验证可能很难。。
发布于 2014-05-23 09:15:45
您可以简化正则表达式,而您使用的正则表达式的错误之处在于,您没有匹配dot周围的方括号
\w+\s?(?:@|at|\[at(?:-sign)?\])\s?\w+\s?(?:\.|\[dot\]|dot)\s?(?:com|us|me)
^^^^^^^regex101演示
不过,如果要删除其他所有内容,则可以使用以下方法:
^(?:.*?(\w+ ?(?:@|at|\[at(?:-sign)?\]) ?\w+ ?(?:\.|\[dot\]|dot) ?(?:com|us|me)).*|.*)$代之以$1。
regex101演示
https://stackoverflow.com/questions/23825016
复制相似问题