Reputation: 33
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
i.e. 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?
Upvotes: 2
Views: 233
Reputation: 91373
As said in comment, don't check . matches newline
.
You could also simplify a bit:
^.*(?:”TEXT TWO”,BB|”TEXT THREE”,AA|”TEXT FOUR”,AA).*\R.*(?:\R|$)
Upvotes: 2