What regex would match a nested table with identifiable text in the table cell? I’ve tried but failed to come up with a regular expression to extract the specific table I want with out grabbing the beginning and end of both tables in the example. Here is something to get started: “<table>.*?</table>“
<table>
<tr>
<td>
<table>
<tr><td>Code1</td></tr>
<tr><td>some data</td></tr>
<tr><td>etc ...</td></tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr><td>Code2</td></tr>
<tr><td>some data</td></tr>
<tr><td>etc ...</td></tr>
</table>
</td>
</tr>
</table>
Say I want to extract the table containing “Code2”. What regex will match specifically and only that table?
The following regex will find your table:
With
(?ms)you turn on “multiline matches”(m)and “dot matches newlines, too”(s). Then you have a negative lookahead(?!)to make sure you have no second start of a table inside your match.