Community
    • Login

    Delete entries and unknown amount of brackets

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 415 Views 1 Watching
    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.
    • Felix LF Offline
      Felix L
      last edited by

      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.

      Alan KilbornA 1 Reply Last reply Reply Quote 2
      • Alan KilbornA Offline
        Alan Kilborn @Felix L
        last edited by Alan Kilborn

        @Felix-L

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

        1 Reply Last reply Reply Quote 4
        • Felix LF Offline
          Felix L
          last edited by

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

          1 Reply Last reply Reply Quote 0

          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors