如何在记事本++中使用正则表达式来搜索具有特定域的电子邮件

时间:2019-03-29 14:39:44

标签: regex

我正在尝试使用记事本++删除以@ domain2.serverdata.net结尾的电子邮件

这是一个字符串示例:

  

smtp:name@domain1.com; SMTP:name@domain2.com; smtp:name@domain2.serverdata.net; smtp:name@domain3.com; smtp:name_e4d1fe3d-e985-40d0-bc65-32c57c9b14d1 @ domain2 .serverdata.net

我希望使用:

  

; smtp:。* @ domain2.serverdata.net

但它也会捕获SMTP:name@domain2.com

4 个答案:

答案 0 :(得分:1)

尝试使用正则表达式:;?smtp:[\w.-]+?@domain2\.serverdata\.net

Demo

答案 1 :(得分:1)

  • Ctrl + H
  • 查找内容:(?:\A|;)smtp:[^@]*@domain2\.serverdata\.net
  • 替换为:LEAVE EMPTY
  • 检查环绕
  • 检查正则表达式
  • 全部替换

说明:

(?:\A|;)                    # non capture group, beginning of file or semicolon, 
                              this allows to delete the first email of the file 
                              that haven't a semicolon before it
smtp:                       # literally
[^@]+                       # 1 or more any character that is not @
@domain2\.serverdata\.net   # literally

答案 2 :(得分:0)

尝试这个:

smtp:[^@]+@domain2\.serverdata\.net(;)?

答案 3 :(得分:0)

正则表达式通常会捕获尽可能多的内容。例如:START.*STOP应用于以下文本:

STARTsghlegdSTOPfsgikbSTARTsvdinusSTOPwegtgw

将捕获此部分:

STARTsghlegdSTOPfsgikbSTARTsvdinusSTOPwegtgw
^------------------------------------^

在您的情况下,.*捕获直到@domain2.serverdata.net的最后一个实例的所有内容。您不想使用.(任何字符),而要使用“ {'1”除外的任何字符,其写法如下:[^@]。 因此,您的完整正则表达式将为smtp:[^@]*@domain2\.serverdata\.net。我还删除了首字母;,因为它会阻止您捕获第一个邮件地址。