Regex matching two lines and results



  • 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



  • 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



  • Thanks a lot!!

    Works great.

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


Log in to reply