简体   繁体   English

在记事本++中删除除特定字符串以外的所有文本

[英]Remove all text except a certain string in Notepad++

I'm extracting case numbers from a wall of text. 我正在从文本墙上提取案例编号。 How do I filter out all the useless text using the replace function in Notepad++ with the help of RegEx? 如何在RegEx的帮助下使用Notepad ++中的替换功能过滤掉所有无用的文本? The parts I want to keep are made up of letters, digits, and a hyphen (SPP-1803-2045227). 我要保留的部分由字母,数字和连字符(SPP-1803-2045227)组成。

I would like to turn this... 我想转这个...

(SPP-1803-2045227)Useless text goes here. 2019-05-18 *
(SPP-1915-1802667)More useless text. 2019-01-14 *
(SPP-1904-1012523)And some more. 2019-02-03 *

...into this: ...变成这样:

SPP-1803-2045227
SPP-1915-1802667
SPP-1904-1012523

I've been playing around with RegEx and also found something in another thread on here before, which wasn't the solution but came very close. 我一直在使用RegEx,并且在此之前的另一个线程中也找到了一些东西,这不是解决方案,但是非常接近。 Unfortunately I can't find it anymore. 不幸的是我找不到了。 It looked something like this: 它看起来像这样:

^(?!S\w+).*\r?\n?

Any help is appreciated. 任何帮助表示赞赏。

you could try something like this. 您可以尝试这样的事情。

find: .*\\((\\w{3}-\\d{4}-\\d{7})\\).* 查找: .*\\((\\w{3}-\\d{4}-\\d{7})\\).*

replace with: \\1 替换为: \\1

The above Regular Expression matches the whole line with your letters and digits between an extra pair of parentheses. 上面的正则表达式使整行与您在另一对括号之间的字母和数字匹配。 When you replace with \\1 you keep only the match between parentheses. \\1替换时,仅保留括号之间的匹配项。

Remember to select Regular Expression Search mode. 记住选择正则表达式搜索模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM