Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Regex删除所有不是电子邮件地址的内容_Regex_Notepad++ - Fatal编程技术网

使用Regex删除所有不是电子邮件地址的内容

使用Regex删除所有不是电子邮件地址的内容,regex,notepad++,Regex,Notepad++,我有一些行包含电子邮件地址和电子邮件地址的隐藏变体,例如,使用[at]而不是@。我想清理这个名单,从一切不是电子邮件地址 TLD是.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

我有一些行包含电子邮件地址和电子邮件地址的隐藏变体,例如,使用
[at]
而不是
@
。我想清理这个名单,从一切不是电子邮件地址

TLD是
.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
我正在使用记事本++搜索和替换,我的尝试是这个
[\w]+(\124;\ s)(@|at\[at\]\[at\]\[at\]\[at sign\](\124; s)[\w]+(\.\124; s)(\.\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%的防弹,因为我读过

您可以稍微简化您的正则表达式,而您使用的正则表达式的错误在于没有匹配
点周围的方括号:

\w+\s?(?:@|at|\[at(?:-sign)?\])\s?\w+\s?(?:\.|\[dot\]|dot)\s?(?:com|us|me)
                                              ^^^^^^^

但是,如果要删除所有其他内容,可以使用以下方法:

^(?:.*?(\w+ ?(?:@|at|\[at(?:-sign)?\]) ?\w+ ?(?:\.|\[dot\]|dot) ?(?:com|us|me)).*|.*)$
并替换为
$1


每行是否始终只有一封电子邮件?我的电子邮件以
.net
结尾,非常有效,仅供参考。哇,太棒了,杰瑞。您的第二个“删除所有其他内容”解决方案在regex101中似乎工作得很好,但在记事本++中替换第十五行时效果很好(示例中包含
JOHNDOE的dot US
完全消失。这是因为区分大小写吗?@LiuKang-Yup,您需要与区分大小写匹配。还有
US
,它是大写的。请注意,出于同样的原因,我还在regex101中使用了
I
标志。