0

I want to match the range between an HTML opening tag <table and a closing tag </table> as long as there is not any opening tag <table inbetween. Example:

<html><body><title>1</title><br><table width=300 height=35 border=0 cellspacing=0 cellpadding=0><tr><td align=center width=50><table width=300 border=0 cellspacing=0 cellpadding=0><tr><td>A</td></tr></table><tr><td><br>B</td></tr></table>
    <br><td><tr></td></tr><table width=300 height=35 border=0 cellspacing=0 cellpadding=0><tr><td align=center width=50><table width=300 border=0 cellspacing=0 cellpadding=0><tr><td>C</td></tr></table><tr><td><br>D</td></tr></table>
    <td><tr></td></tr><br><table width=300 height=35 border=0 cellspacing=0 cellpadding=0><tr><td align=center width=50><table width=300 border=0 cellspacing=0 cellpadding=0><tr><td>E</td></tr></table><tr><td><br>F</td></tr></table>

Each <table which is eventually followed by another <table before reaching </table should be disregarded. Consequently, the first match should be:

<table width=300 border=0 cellspacing=0 cellpadding=0><tr><td>A</td></tr></table>

The match should not be:

<table width=300 height=35 border=0 cellspacing=0 cellpadding=0><tr><td align=center width=50><table width=300 border=0 cellspacing=0 cellpadding=0><tr><td>A</td></tr></table>

...and so on.

Regex tried: (<table(?!<table)(.+?)</table>)

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
Pixy
  • 47
  • 6
  • Please edit your question and include regex you used directly within question. Question needs to be standalone and should not require visiting outside links. – Dalija Prasnikar Feb 05 '23 at 09:01
  • How about this, `]*>.*?<\/table>`, https://regex101.com/r/q8BGCl/1, no need for lookarounds
    – Buttered_Toast Feb 05 '23 at 10:20
  • @Buttered_Toast nice, but top-level tables are still matched. – Pixy Feb 05 '23 at 10:23
  • https://www.rexegg.com/regex-quantifiers.html#tempered_greed, https://stackoverflow.com/questions/37240408/regular-expressions-ensuring-b-doesnt-come-between-a-and-c – bobble bubble Feb 05 '23 at 10:30
  • Why was this Q tagged [Delphi](https://stackoverflow.com/questions/tagged/delphi)? You didn't even mention it, let alone making it important. – AmigoJack Feb 05 '23 at 11:27

0 Answers0