• Login
Community
  • Login

Delete entries and unknown amount of brackets

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 220 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F
    Felix L
    last edited by May 16, 2023, 11:22 AM

    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 CHECKED

    Unfortunately, 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.

    A 1 Reply Last reply May 16, 2023, 11:52 AM Reply Quote 2
    • A
      Alan Kilborn @Felix L
      last edited by Alan Kilborn May 16, 2023, 11:53 AM May 16, 2023, 11:52 AM

      @Felix-L

      Maybe try a Find what of: (?-s)^\R(?:\\[.+\\]\R)+\Rasd[0-2]\R

      1 Reply Last reply Reply Quote 4
      • F
        Felix L
        last edited by May 16, 2023, 12:17 PM

        @Alan-Kilborn You’re just awesome dude, thank you very much. Works like a charm.

        1 Reply Last reply Reply Quote 0
        2 out of 3
        • First post
          2/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors