正则表达式仅保留电子邮件:密码

正则表达式仅保留电子邮件:密码

我只想保留电子邮件和密码并删除所有其他信息。

Name: Test1 Test1
Address: 11 Test Road
Country : Test1
Post Code: abc111
EmailPass : [email protected]:password111$£*!


Name: Test2 Test2
Address: 22 Test Road
Country : Test2
Post Code: abc222
EmailPass : [email protected]:password222$£*!

我想要的是

[email protected]:password111$£*!
[email protected]:password222$£*!

答案1

这将匹配电子邮件仅有的EmailPass :

  • Ctrl+H
  • 找什么:.+?EmailPass : (\S+@\S+)
  • 用。。。来代替:$1\n
  • 取消选中 相符
  • 查看 环绕
  • 查看 正则表达式
  • 查看 . matches newline
  • Replace all

解释:

.+?             # 1 or more any character, not greedy
EmailPass :     # literally
(               # group 1
    \S+             # 1 or more non space
    @               # @
    \S+             # 1 or more non space
)               # end group

替代品:

$1      # content of group 1, the email
\n      # a linebreak, you can use \r\n for Windows EOL

截图(之前):

在此处输入图片描述

截图(之后):

在此处输入图片描述

答案2

@这仅匹配正确的电子邮件(包含和和文本的电子邮件.)。它还确保在之后:提供了密码。

(?s).*?(\S+@\S+\.\S+:\S+)|.+

用。。。来代替\1\n

输入示例:

Post Code: abc111
EmailPass : [email protected]:password222$£*!

Post Code: abc222
EmailPass : test_222@gmail.:password222$£*!

Post Code: abc111
EmailPass : [email protected]:

Post Code: abc111
EmailPass : [email protected]:password333$£*!

结果:

[email protected]:password222$£*!
[email protected]:password333$£*!

演示

相关内容