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] qwe0Here is how I would like that data to look (“after” data):
[some text] [some text] xyz2 [some text] [some text] [some text] qwe0To 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login