我有一个5MB的文本文件,我需要找到所有的电子邮件地址并删除其他所有内容。
文本文件包含以下代码段中的项目:
<snip>
To: (Address)
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=49ee46a4d9da8492a8d0583f9b13225d5-Claire D
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=a1525d3se9057487d9cacdec1562b7281-Big Tang;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=92414e086e5540d890bg1372316f15222-Matt Perry
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=3c776ca5d813948559a705db141bf0100-Vijay Boy;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=49ee4s6a49da8492a8d0583f9b13225d5-Claire N
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=6e799gd02635149138e4c9d152ab0357e-Becky G
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=f65ed21e081g54effad7c9b4f0778f2b8-Ham Ly
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=d875920114ga748e99f045dbac3e34372-Brad King
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8d945fcc838gb49af822e17b6a3f641b7-Bharat Mass
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8514631915374ef88g3b382f4b7d2d4b2-Pratboss;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=a1525d3e9057487d9cacgdec1562b7281-Huy Tang;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8bc63496da41481fb02fbgcf359c029b1-Dolly Age
sales@trol.com
Joey.Boss@BCape.com
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=cddab36g026d64df993ca28a445354c0a-Dilshad A.
Joey.Boss@BCape.com
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=9843f7566d374cb7ac634637098gc3633-Orewell Dme;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=2198f33e85a24ebab276g2ea14g2415216-Mind God;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=7ea70e47dc7841a7ag007bfdba21feaf4-Prabhu Dist;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8d945fcc838b49afg822e17b6a3f641b7-Bharat Mass
</snip>
我能够研究如何使用正则表达式在Editplus中查找电子邮件地址。我只是无法找出find / replace命令来删除除电子邮件地址之外的所有内容,并确保电子邮件地址被一行分开。
下面放入Editplus find命令时,给我发电子邮件:
[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\.\-_]+\.[a-zA-Z0-9\.\-_]+
我很感谢帮助删除除电子邮件地址之外的所有内容。
答案 0 :(得分:0)
([a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\.\-_]+\.[a-zA-Z0-9\.\-_]+)|.
替换为: $1
我将表达式包装到( ..your expression.. )|.
然后只需替换所有内容,如果要替换的子字符串是与您的表达式匹配的电子邮件地址,那么它将被捕获到$1
并替换为返回字符串
现场演示
https://regex101.com/r/kY5dU8/1
示例文字
<snip>
To: (Address)
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=49ee46a4d9da8492a8d0583f9b13225d5-Claire D
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=a1525d3se9057487d9cacdec1562b7281-Big Tang;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=92414e086e5540d890bg1372316f15222-Matt Perry
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=3c776ca5d813948559a705db141bf0100-Vijay Boy;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=49ee4s6a49da8492a8d0583f9b13225d5-Claire N
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=6e799gd02635149138e4c9d152ab0357e-Becky G
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=f65ed21e081g54effad7c9b4f0778f2b8-Ham Ly
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=d875920114ga748e99f045dbac3e34372-Brad King
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8d945fcc838gb49af822e17b6a3f641b7-Bharat Mass
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8514631915374ef88g3b382f4b7d2d4b2-Pratboss;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=a1525d3e9057487d9cacgdec1562b7281-Huy Tang;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8bc63496da41481fb02fbgcf359c029b1-Dolly Age
sales@trol.com
Joey.Boss@BCape.com
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=cddab36g026d64df993ca28a445354c0a-Dilshad A.
Joey.Boss@BCape.com
/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=9843f7566d374cb7ac634637098gc3633-Orewell Dme;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=2198f33e85a24ebab276g2ea14g2415216-Mind God;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=7ea70e47dc7841a7ag007bfdba21feaf4-Prabhu Dist;/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLTM)/cn=Recipients/cn=8d945fcc838b49afg822e17b6a3f641b7-Bharat Mass
</snip>
替换后
sales@trol.com
Joey.Boss@BCape.com
Joey.Boss@BCape.com
NODE EXPLANATION
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
[a-zA-Z0-9\.\-_]+ any character of: 'a' to 'z', 'A' to
'Z', '0' to '9', '\.', '\-', '_' (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
@ '@'
----------------------------------------------------------------------
[a-zA-Z0-9\.\-_]+ any character of: 'a' to 'z', 'A' to
'Z', '0' to '9', '\.', '\-', '_' (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\. '.'
----------------------------------------------------------------------
[a-zA-Z0-9\.\-_]+ any character of: 'a' to 'z', 'A' to
'Z', '0' to '9', '\.', '\-', '_' (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
. any character except \n
----------------------------------------------------------------------
答案 1 :(得分:0)
这真的不复杂,特别是如果你打破了任务。
根据您的正则表达式,电子邮件地址必须有@
标志。所以我使用这个正则表达式(启用多行/全局模式)使用全局替换:
^[^@]+$
结果是:
sales@trol.com
Joey.Boss@BCape.com
Joey.Boss@BCape.com
现在,您只需要用换行符替换多个空格,这可以通过此正则表达式完成:
\s+
对于您的数据,我建议您考虑使用一个或两个简单的正则表达式来保持可读性。像这样的正则表达式将为您提供迄今为止最佳的性能(other answer需要超过10,000步才能完成,与我的相比,只需要60或者1000%的速度给予或接受)。