Search code examples
regexregex-greedy

How to select with regex multiple lines with two or even more conditional groups/matches?


I need in this kind of files to search for [Documentation] and when it find then to select text in first line. If next row starts with space then three dots and spaces select also text from all such lines.

@{TEST_SCREENS_WITH_TIMEOUT}    ShowDesc    ShowOsAndCountryCode    ShowSW  
...                             Checksum_PPSU   Checksum_BPSU                   
...                             Datetime_Clock  Datetime_DDMM
...                             ShowHWRevBaseboard  ShowHWRevSOM

*** Keywords ***
Program Version contain
[Documentation]     Read out program version and compare it with
    ...                 Comparison is done with "Should Contain"
    ...                 it checks if 

Tarif EPS is
[Documentation]     Read out tarif EPS and compare it with ${TARIF_EPS}
    ...                 Comparison is done with "Should be equal"
[Arguments]         ${TARIF_EPS}

Should be equal    ${disp_traf_eps}    ${TARIF_EPS}    Tarif EPS


Release Date contain
[Documentation] Read out program version and compare it with ${RELEASE_DATE}

This is what I manage to get till now:
^\s*[Documentation]\s+(.+)(?:(?=\s+...\s+(.+)))*

Entire text and regex I have tried so far can be found here: https://regex101.com/r/Jbzd4e/1

In my case it only selects 2 rows. I need to select only Documentation text!


Solution

  • How about this: ^\s{1,}\[Documentation]\s*(.*)$|^\s{1,}\.{3}\s*(.*)$

    https://regex101.com/r/C5FTzP/2

    Update;

    Or this might be more elegant: ^\s{1,}(\[Documentation]|\.{3})\s*(.*)$

    https://regex101.com/r/C5FTzP/4