I have a list like following:
tttttttttttyyyyyyyyyyyyyy 28758.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28759.gif: 98.92%
tttttttttttyyyyyyyyyyyyyy 28760.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28761.gif: 98.54%
tttttttttttyyyyyyyyyyyyyy 28762.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28763.gif: 98.85%
tttttttttttyyyyyyyyyyyyyy 28764.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28765.gif: 99.91%
tttttttttttyyyyyyyyyyyyyy 28766.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28767.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28768.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28834.gif: 100.00%
tttttttttttyyyyyyyyyyyyyy 28835.gif: 100.00%
The following regex bookmarks all lines that include a percentage number under 100.00%:
\b\d{2}\.\d{2}\b%
Now I need a regex that bookmarks all lines including a percentage number under 100.00% and two lines after the target line
The following regex can bookmark my target lines and just one line after them:
(?-s)(^.+\R?)\b\d{2}\.\d{2}\b%(?:\R^.+)?
I tried following regex but I failed:
(?-s)(^.+\R?)\b\d{2}\.\d{2}\b%(?:\R^.+)?(?:\R^.+)
where is my regex problem?
Because your regex consumes the lines has percentage lower than 100.00%
.
unmatched tttttttttttyyyyyyyyyyyyyy 28758.gif: 100.00%
matched tttttttttttyyyyyyyyyyyyyy 28759.gif: 98.92%
consumed tttttttttttyyyyyyyyyyyyyy 28760.gif: 100.00%
consumed tttttttttttyyyyyyyyyyyyyy 28761.gif: 98.54%
unmatched tttttttttttyyyyyyyyyyyyyy 28762.gif: 100.00%
Notice the 4th line didn't match because your regex consumed it due to the "two lines after the target line" rule.
There are two ways to fix it.
This way the 2 lines after the target line will still be matched and back-referenced but not consumed. But it creates overlapped matches.
(?-s)(^.+\R?)\b\d{2}\.\d{2}\b%(?=((?:\R^.+){2}))
100.00%
This way it will matches the next 0 to 2 lines, depends on the percentages of these lines.
(?-s)(^.+\R?)\b\d{2}\.\d{2}\b%(?:\R^(?!.*\b\d{2}\.\d{2}\b%).+){0,2}
Depends on your needs, these two should work for most of your cases.