Thought greed would work for me, but something went wrong. There is an approximate code from which it is necessary to capture the second tablet. Between the plates there may be another html code, including plates of another plan. Now even add for completeness example:

<p>Текст</p> <table> <tr> <td>разные данные</td> </tr> </table> <table> <tr> <td>Режим</td> </tr> <tr> <td>Тратата</td> </tr> </table> <p>Текст</p> <table> <tr> <td>Время</td> </tr> <tr> <td>Тратата</td> </tr> </table> 

Tried to do so ^

 <table.+?Время.+?</table> 

Working example https://regex101.com/r/ltMG7J/2

I tried to do a positive peering back (?<=...) , but the service is tricked by the points / pluses inside the positive peering brackets.

Failed questions :

1) How can I choose a sign on the example of the regulars above? (plates can be many different, I can not bind to specific these 3 plates).

2) already solved the problem : how can I throw the second tablet (mode) at the end of the html?

  • The first .+? you do not work as you want, because the limiter is Время , not </table> for it. - Visman
  • You can do this regex101.com/r/ltMG7J/3 - Visman
  • @Visman and how to reveal the meaning of this? (?:(?!</?table>).)+? ==== .+? but if there is no ahead </?table> ? - Jean-Claude
  • In .+? A restriction has been introduced so that there is no <table> and </table> inside. Verification occurs when each character is selected, for which the group (?:.)+? entered (?:.)+? without feedback. - Visman
  • one
    On large texts, the increase will be greater. Just from doing nothing optimized, I do not pretend to anything. - ReinRaus

1 answer 1

My response from the comments:

 <table(?:(?!</?table>).)+?Время.+?</table> 

Test https://regex101.com/r/ltMG7J/3

First .+? A restriction has been introduced so that there is no <table> and </table> inside. Verification occurs when each character is selected, for which the group (?:.)+? entered (?:.)+? without feedback.

The optimized version of @ReinRaus here https://regex101.com/r/ltMG7J/4 eliminates unnecessary checks for characters other than < and В.

  • and where to read about character-by-character verification without feedback and other similar solutions that are not written about in popular books? - Jean-Claude
  • @ Jean-Claude, I will not tell you. Just over time comes an understanding of how to solve this or that problem. Experience in drafting regulars is important. - Visman
  • @ Edward has long read. - Jean-Claude