I am trying to use re.sub() to change all html tags < and > to { and }. Here's the catch: I only want to change the matches between <table and </table>.
I can't for the life of me find a regex tutorial or post where one is able to change every regex match, but only between two other regex matches. I've looked at positive/negative lookahead and lookbehind tutorials, etc. but no luck. It's been a good few hours of searching before deciding to post.
Here is the best I've got so far:
(?<=<table)(?:.*?)(<)(?:.*)(?=<\/table>)
This will match one "<" between the table begin and end tags, but I don't know how to get it to match more than one. I've played around with making the any-character groups lazy or not lazy, etc. but no luck.
The point of all this is, I have a string with lots of HTML and I want to keep all of the HTML tags within tables, as well as the tables themselves.
My current plan is to change all of the tags within tables (and the table tags themselves) to either { or }, then delete all HTML tags < and > in the entire document, then change all { and } back to < and >. Doing this should preserve the tables (and any other tags inside).
Example of Input:
<font style = "font-family:inherit>
<any other HTML tags>
random text
<table cellpadding="0" cellspacing="0" style="font-family:times new
roman;font-size:10pt;width:100%;border-collapse:collapse;text-align:left;">
<tr>
<td colspan="3">
<font style="font-family:inherit;font-size:12pt;font-
weight:bold;">washington, d.c. 20549</font>
random text
<any other HTML tags within table tags>
</td>
</table>
random text
<font style = "font-family:inherit>
Example of Output:
<font style = "font-family:inherit>
<any other HTML tags>
random text
{table cellpadding="0" cellspacing="0" style="font-family:times new
roman;font-size:10pt;width:100%;border-collapse:collapse;text-align:left;"}
{tr}
{td colspan="3"}
{font style="font-family:inherit;font-size:12pt;font-
weight:bold;"}washington, d.c. 20549{/font}
random text
{any other HTML tags within table tags}
{/td}
{/table}
random text
<font style = "font-family:inherit>
Thank you, Grog