简体   繁体   中英

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

"TEXT THREE",AA

"TEXT FOUR",AA

Typical file (will be 1000's of lines long) contents:

#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.

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. If I do the 'Replace', it says it has replaced 86 matches – BUT it has actually removed thousands of lines. 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 .

You could also simplify a bit:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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