Community
    • Login

    Regex matching two lines and results

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 5.4k 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.
    • iyxI
      iyx
      last edited by

      Hi, I have simple regex matching two lines .+something.+youtu.+\n.+

      which correctly matches first and subsequent line, but “Find All in Current Document” only shows the first line in results.

      Is there some way to have both matched lines also in the results window?

      Thanks

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

        Hello, @iyx,

        I suppose that you want every second line, following the line which matches, in the Find Result panel, for copying in an other file. If so, here is, below, a possible method. I suppose we are searching for the string WordA and for each line following this one :

        • Open the Mark dialog with the menu option Search > Mark…

        • In the Find what: box, type the regex ^.*WordA.*\R

        • Click on the Mark All button

        Note : This regex matches any entire line, containing the string WordA

        • Then, add the part \K.*\R, in order to get the regex ^.*WordA.*\R\K.*\R, in the Find what: box

        • Again, click on the Mark All feature

        Note : This second regex search first, as above, for any line containing the string WordA. Then, due to the \K syntax the search position is reset and it, now, searches for the second complete line .*\R

        • Then, use the menu option Search > Bookmark > Copy Bookmarked lines

        • Paste all these bookmarked lines in a new tab

        Et voilà !

        So let’s imagine a test, with the original text, below :

        WordA
        Line 2
        Line 3
        Line 4
        123WordA
        Line 6
        Line 7
        WordA 789
        Line 9
        123WordA789
        Line 11
        Line 12
        Line 13
        Line 14
        123WordA999
        
        
        0000WordA999
        WordA---Line 19
        Line20---WordA
        Line 21
        Line 22
        ___WordA___
        Line 24
        Line 25
        Line 26
        End of Test ( WordA )
        

        Just note 3 particularities :

        • The line 123WordA999 is followed by two blank lines

        • The consecutive lines 18, 19 and 20 contains, each, the string WordA

        • The last line, End of Test ( WordA ), is not followed by any line

        After the two Mark actions, the bookmarked lines should be :

        WordA
        Line 2
        123WordA
        Line 6
        WordA 789
        Line 9
        123WordA789
        Line 11
        123WordA999
        
        0000WordA999
        WordA---Line 19
        Line20---WordA
        Line 21
        ___WordA___
        Line 24
        End of Test ( WordA )
        

        Remark : If your searching for, let’s say, the three strings WordA, WordB and WordC, in that order, just replace, in the regexes, above, the string WordA by the regex WordA.*WordB.*WordC

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • iyxI
          iyx
          last edited by

          Thanks a lot!!

          Works great.

          (“Bookmark line” need to be checked, but that’s obvious)

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