• Login
Community
  • Login

Efficiently select/copy bookmarked lines and their collapsed contents altogether?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 3 Posters 628 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
    Fermi
    last edited by Feb 18, 2025, 10:21 PM

    I have bunch of sections and collapsed contents (ie. .ini format) shown.
    603c5471-285f-4421-9f85-0ae764005a68-image.png

    I’ve identified the keyword of interest (ie. “positive” in this case) by Bookmark line" & “Mark All”) and would like to select/copy both the bookmarked lines and their content collapsed in the bookmarked lines (ie. line 1-3, 4-6, 10-12).

    915dd84f-b0ad-412b-b0f1-c2d7208efeed-image.png

    How can I select/copy both bookmarked and collapsed lines within more efficiently, without actually unfolding, for example, the section 1 to select line 2-3?

    I’ve hovered Ctrl + mouse manually from the beginning of the bookmarker lines of interest for line selection. Can Notepad++ select/copy the lines in the bookmarked/collapsed easily?

    Thanks for comments.

    A M 2 Replies Last reply Feb 19, 2025, 12:39 AM Reply Quote 0
    • A
      Alan Kilborn @Fermi
      last edited by Feb 19, 2025, 12:39 AM

      @Fermi

      So, the following has nothing to do with bookmarks at all…

      But if you put your caret at the beginning of line 4 and press Shift + DownArrow, line 4 will appear selected and your caret will be at the start of line 7. If you then press Ctrl+c, the text copied will include lines 4, 5 and 6.

      If you’re looking for more “advanced” functionality than that, you’re out of luck.

      1 Reply Last reply Reply Quote 1
      • M
        mkupper @Fermi
        last edited by Feb 19, 2025, 6:19 PM

        @Fermi If your data closely matches the layout that you showin your screen shots then try this:

        Step 1 - add one line at the bottom of the file that has

        [section999, end]
        

        The exact details of that line do not matter other than we want the [section999 part.

        Step 2 - Do a Mark-all using this regular expression

        ^(\[section[0-9]+, positive\]\R(?:(?!\[section[0-9]+).+\R)*)+
        

        If you experiment with searching using that expression you will find that it matches blocks of consecutive positive sections. The reason for the [section999, end] line is to deal with if the last section is positive and there is stuff after that section that you don’t want.

        If you don’t have stuff in the file after the last section then you don’t need the [section999, end] line.

        If you have blank lines in your sections then change the (?!\[section[0-9]+).+ part to (?!\[section[0-9]+).* As it is, if you have no blank lines then you can use .+ and instead of an [section999, end] line you can add one blank line.

        Step 3 - Do a mark-all and then Copy-all-marked lines.

        That will load all of the positive sections into the copy/ paste buffer in one shot.

        Here’s the breakdown of what’s happening in

        ^(\[section[0-9]+, positive\]\R(?:(?!\[section[0-9]+).+\R)*)+
        
        1. The outer ^( … )+ parentheses allow for consectitive positive blocks. This is optional as we are doing a mark-all Having this makes a plain search to see what it makes make more sense.
        2. The \[section[0-9]+, positive\]\R part matches the start of a positive section.
        3. Right after that is (?:(?!\[section[0-9]+).*\R)* which matches zero or more lines within a section with the end of the match being the start of the next section. Essentially, I’m matching all lines that do not start with \[section[0-9]+. If your data includes lines that start with something line [section999 then you may need to expand that part of the regexp.
        F 1 Reply Last reply Feb 19, 2025, 9:11 PM Reply Quote 4
        • F
          Fermi @mkupper
          last edited by Fermi Feb 19, 2025, 9:33 PM Feb 19, 2025, 9:11 PM

          This post is deleted!
          M F 2 Replies Last reply Feb 19, 2025, 9:50 PM Reply Quote 1
          • M
            mkupper @Fermi
            last edited by Feb 19, 2025, 9:50 PM

            @Fermi said in Efficiently select/copy bookmarked lines and their collapsed contents altogether?:

            I guess I’ve over-simplified the problem earlier. I’m having something more general like: [long_random_stringx_sectiony, positive, long_random_stringy] as the section header.

            Please take a look at FAQ: Request for Help without sufficient information to help you. I think that will help you ask a question here where the answers you get will be useful or helpful to you.

            1 Reply Last reply Reply Quote 2
            • F
              Fermi @Fermi
              last edited by Fermi Feb 20, 2025, 5:12 PM Feb 20, 2025, 4:42 PM

              @mkupper
              In a generic form (.ini), I want to select the header and its contents, where the header/comment before/after the keyword (ie. positive) are unique.

              [unique_header1]; positive, unique_comment1
              aaa
              ...
              [unique_header2]; negative, unique_comment2
              bbb
              ...
              [unique_header3]; positive, unique_comment3
              ccc
              ...
              [unique_headerz]; positive, unique_commentz
              zzz
              ...
              

              What modification should I have to the regex? Thanks.

              M 1 Reply Last reply Feb 22, 2025, 2:50 AM Reply Quote 0
              • M
                mkupper @Fermi
                last edited by Feb 22, 2025, 2:50 AM

                @Fermi said in Efficiently select/copy bookmarked lines and their collapsed contents altogether?:

                In a generic form (.ini), I want to select the header and its contents, where the header/comment before/after the keyword (ie. positive) are unique.

                Ideally, regular expressions are constructed to match only the data you want it to match and will not match anything else. You don’t want false positives nor false negatives.

                As you seem unwilling or unable to provide examples of the data you are attempting to match any help we provide here will also need to be generic or vague. To complicate things, you also seem to be shifting the goalposts of what a section header looks like.

                I decided to define a section header as a line that starts with a [ and that anything else is not a section header line. With that in mind, here is a rather general regular expression that will match the positive sections:

                (?-i)^\[.*[,;] *positive,.*\R(?:(?!\[).*\R)*
                

                That expression has two main parts

                • (?-i)^\[.*[,;] *positive,.*\R matches the section header lines we are interested in.
                • (?:(?!\[).*\R)* matches zero or more lines that are not section header lines.

                Reading the (?-i)^\[.*[,;] *positive,.*\R part from left to right we have:

                • (?-i) Turns off the ignore-case option so that we only match a lower case positive. If your data includes things such as Positive or POSITIVE then you should use (?i) instead of (?-i).
                • ^ matches the start of a line,
                • \[ matches a [. We need the \ as [s have a special meaning within regular expressions. Using \[ says to look for a normal [.
                • .* matches zero to any number of characters.
                • [,;] matches either a comma or semicolon. When you first posted you had commas and now you have semicolons. That’s fine, we can handle either or both and so I went with both.
                • * matches zero to any number of spaces between the [,;] and the positive.
                • positive, matches the word positive followed by a comma.
                • .* matches zero to any number of characters. This will run to the end of the line.
                • \R matches the end of line characters themselves.

                The second part with (?:(?!\[).*\R)* is slightly convoluted as I also want to match empty or blank lines and to include those in the section.

                • The (?: and )* outer parentheses and their decoration says to repeat the stuff that’s inside zero or more times.
                • (?!\[).*\R is the inner part and it matches any line that does not start with a [.
                1 Reply Last reply Reply Quote 4
                6 out of 7
                • First post
                  6/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors