简体   繁体   English

正则表达式在记事本++中查找/替换多个文本

[英]Regex find/replace multiple text in Notepad++

I'm struggling a bit with some regex find/replace..我在一些正则表达式查找/替换方面有点挣扎..

I want to search for some terms and when it finds any of them, it removes the line they're on and the next line.我想搜索一些术语,当它找到任何一个时,它会删除它们所在的行和下一行。 Terms I want to search for will have quotation marks and commas in them.我要搜索的术语中将包含引号和逗号。

These are typical search terms (inc. the quotation marks):这些是典型的搜索词(包括引号):

"TEXT TWO",BB “文字二”,BB

"TEXT THREE",AA 《文字三》,AA

"TEXT FOUR",AA 《文字四》,AA

Typical file (will be 1000's of lines long) contents:典型文件(将有 1000 行长)内容:

#text:0 first="blah" second="TEXT ONE",AA | more text
Line 1
#text:0 first="blah" second="TEXT TWO",BB | more text
Line 2
#text:0 first="blah" second="TEXT THREE",AA | more text
Line 3
#text:0 first="blah" second="TEXT FOUR",BB | more text
Line 4
#text:0 first="blah" second="TEXT THREE",AA | more text
Line 5
#text:0 first="blah" second="TEXT FOUR",AA | more text
Line 2

I'd like the result to be:我希望结果是:

#text:0 first="blah" second="TEXT ONE",AA | more text
Line 1
#text:0 first="blah" second="TEXT FOUR",BB | more text
Line 4

ie any line containing any of the above 3 terms would be completely deleted - along with its following line.即,包含上述 3 个术语中的任何一个的任何行都将被完全删除 - 连同其下一行。

I tried a regex search/replace of:我尝试了正则表达式搜索/替换:

Find what:-找什么:-

.*"TEXT TWO",BB.*\R.*(?:\R|$)|.*"TEXT THREE",AA.*\R.*(?:\R|$)|.*"TEXT FOUR",AA.*\R.*(?:\R|$)

Replace with:- (left blank)替换为:-(留空)

When I do the 'find' and 'count' , it correctly says 86 matches.当我执行 'find' 和 'count' 时,它正确地显示了 86 个匹配项。 If I do the 'Replace', it says it has replaced 86 matches – BUT it has actually removed thousands of lines.如果我执行“替换”,它会说它已经替换了 86 个匹配项——但它实际上已经删除了数千行。 Confused… Can you help please?困惑......你能帮忙吗? Do I need some extra quotations or escape characters?我需要一些额外的引号或转义字符吗?

As said in comment, don't check . matches newline正如评论中所说,不要检查. matches newline . matches newline . . matches newline

You could also simplify a bit:你也可以简化一点:

^.*(?:”TEXT TWO”,BB|”TEXT THREE”,AA|”TEXT FOUR”,AA).*\R.*(?:\R|$)

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

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