如何 select 使用带有两个或更多条件 groups/matches 的正则表达式多行?
How to select with regex multiple lines with two or even more conditional groups/matches?
我需要在此类文件中搜索 [Documentation],然后在第一行找到 select 文本。如果下一行以 space 开头,那么三个点和 spaces select 也是来自所有这些行的文本。
@{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}
这是我到目前为止设法得到的:
^\s*[文档]\s+(.+)(?:(?=\s+...\s+(.+)))*
到目前为止我尝试过的完整文本和正则表达式可以在这里找到:https://regex101.com/r/Jbzd4e/1
在我的例子中它只有 selects 2 行。我只需要 select 文档文本!
这个怎么样:^\s{1,}\[Documentation]\s*(.*)$|^\s{1,}\.{3}\s*(.*)$
https://regex101.com/r/C5FTzP/2
更新;
或者这可能更优雅:^\s{1,}(\[Documentation]|\.{3})\s*(.*)$
我需要在此类文件中搜索 [Documentation],然后在第一行找到 select 文本。如果下一行以 space 开头,那么三个点和 spaces select 也是来自所有这些行的文本。
@{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}
这是我到目前为止设法得到的:
^\s*[文档]\s+(.+)(?:(?=\s+...\s+(.+)))*
到目前为止我尝试过的完整文本和正则表达式可以在这里找到:https://regex101.com/r/Jbzd4e/1
在我的例子中它只有 selects 2 行。我只需要 select 文档文本!
这个怎么样:^\s{1,}\[Documentation]\s*(.*)$|^\s{1,}\.{3}\s*(.*)$
https://regex101.com/r/C5FTzP/2
更新;
或者这可能更优雅:^\s{1,}(\[Documentation]|\.{3})\s*(.*)$