Delete entries and unknown amount of brackets
-
Fellow Notepad++ Users,
Could you please help me with the following search-and-replace problem I am having?
I have a file with thousands of entries that always have the same structure: an unknown amount of square brackets with changing content followed by a string that doesn’t have any square brackets.
How do I delete entries with the string “asd” and all their square brackets above? (as shown in the example)
Additional (hopefully helpful) information:
- There are no nested brackets.
- There always is exactly one empty line between the last right parenthesis of an entry and its “free” string, and also exactly one empty line between two entries.
- The last character of an entry always is a 0, 1 or 2.
Here is the data I currently have (“before” data):
[some text] [some text] xyz2 [some text] [some text] [some text] [some text] asd1 [some text] [some text] [some text] qwe0
Here is how I would like that data to look (“after” data):
[some text] [some text] xyz2 [some text] [some text] [some text] qwe0
To accomplish this, I have tried using the following Find/Replace expressions and settings
Find What =
]\r\n\r\nasd([0-2]{1})\r\n
Replace With =nothing
Search Mode = REGULAR EXPRESSION
Dot Matches Newline = NOT CHECKEDUnfortunately, I’m not sure how to account for the unnkown amount of brackets in my search. Could you please help me find the solution?
Thank you.
-
Maybe try a Find what of:
(?-s)^\R(?:\\[.+\\]\R)+\Rasd[0-2]\R
-
@Alan-Kilborn You’re just awesome dude, thank you very much. Works like a charm.