Community
    • Login

    Is it possible to copy mult line regex output that is marked/bookmarked?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 2.6k 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.
    • Varun MuralidharanV
      Varun Muralidharan
      last edited by

      I have enabled “.” matches new line character. This is to get the required result I need. Using the regex I find all possibilities. It gives me mult line regex output which is as expected.
      Now when I mark all with bookmark then, “Mark” feature selects the exact lines I need but “bookmark” feature only bookmarks the first line of the regex multi line output.

      Hence I am unable to copy the multi line output.
      Please let me know if it is possible to achieve what I intended to.

      Thanks,
      Varun

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hi Varun,

        Don’t worry ! Indeed, there’s a solution, although a bit difficult to explain !!

        So let’s start with that small sorted list of picture files, below :

        AU.png                      286      31/05/2016
        arrow2.png                  332      11/08/2016
        arrow_bot.gif               164      11/03/2016
        arrow_down.png              190      09/08/2016
        arrow_off.png               180      20/08/2016
        arrow_sprite.png            260      10/08/2016
        arrow_up.png                 45      09/12/2016
        arrow_up.png                189      09/08/2016
        arrowbefore.gif              52      01/01/2016
        arrowbefore.gif              79      17/03/2016
        arrowbefore.gif             125      09/08/2016
        ast.png                     164      29/08/2016
        attention.gif               209      25/05/2016
        attention.gif               359      10/03/2016
        attention.gif               574      08/03/2016
        back2.gif                    78      26/03/2016
        backward_disabled.gif        63      04/08/2016
        backward_enabled.gif         63      04/08/2016
        backward_enabled.gif         78      26/03/2016
        

        In that list, some files are present two or three times, but with different sizes and modification dates². Let suppose that we would like to bookmark all the files which are present several times, in order to copy them, afterwards, in a new tab !

        To find any file, present 3 times, we can use the regex (?-s)^(.{25}).+\R\1.+\R\1, which tries to match tree consecutives lines, with the first 25 characters, identical on these 3 lines. As the regex begins to search for the 25 first characters of the first line, only this first line, out of the three ones, will be marked. Logical !

        Now, to mark the second line of any group of three consecutives lines, with the first 25 characters identical, we’ll use the regex (?-s)^(.{25}).+\R\K\1.+\R\1

        Notes :

        • The (?-s) modifier, in front of the regex, forces the regex engine to consider that the dot matches standard character, ONLY !

        • The \K syntax reset the position of search of the regex engine. So, it forgets anything that what previously matched before the \K form. Therefore, it just tries to match the regex \1.+\R\1, that is to say the complete second line and the first 25 characters of the third line, from each group of 3 lines !

        Finally to mark the third line, of any group of 3 lines, we’ll use the regex (?-s)^(.{25}).+\R\1.+\R\K\1. This time, once the \K form read, it just matches the regex \1, which corresponds to the 25 first characters of the third line of any group of 3 lines !

        To end with, we need to find any file, present 2 times, only. We are going to use the same method. So, we’ll use the regex (?-s)^(.{25}).+\R\1, which will mark the first lines, out of the two lines of each group

        Then, in order to mark the second line, of each group of 2 lines, we’ll use the regex (?-s)^(.{25}).+\R\K\1

        Finally, after using the menu commands Search - Bookmark - Cut Bookmarked Lines OR Search - Bookmark - Copy Bookmarked Lines and pasting in a new tab, we get the list of all the items, present 2 or 3 times !

        arrow_up.png                 45      09/12/2016
        arrow_up.png                189      09/08/2016
        arrowbefore.gif              52      01/01/2016
        arrowbefore.gif              79      17/03/2016
        arrowbefore.gif             125      09/08/2016
        attention.gif               209      25/05/2016
        attention.gif               359      10/03/2016
        attention.gif               574      08/03/2016
        backward_enabled.gif         63      04/08/2016
        backward_enabled.gif         78      26/03/2016
        

        Let’s examine a second example, where a sorted list of lines contains some consecutive lines, quite *identical. In order to mark any line of these blocks, formed of identical lines, we’ll just need TWO generic regexes :

        • The regex ^(.+\R)(?=\1), which will mark all the lines, but the last, of each group of consecutive identical lines

        • The regex ^((.+)\R)\1*\2\K\R, which will mark the last line of each block of consecutive identical lines

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • Scott SumnerS
          Scott Sumner
          last edited by

          This posting may also be helpful to the OP; even though it is about deleting rather than copying, I think it still has some relevant info: https://notepad-plus-plus.org/community/topic/12192/remove-unmarked-lines-not-just-unbookmarked-lines

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