title: Regular Expression (regex) to Parse HTML Segment
body: <p>I am currently trying to come up with a regular expression that will parse out something like the following:</p>
  
  <p><strong>ORIGINAL HTML:</strong></p>
  
  <pre><code>&lt;td align="center"&gt;&lt;p&gt;line 1&lt;/p&gt;&lt;p&gt;line 2&lt;/p&gt;&lt;p&gt;line 3&lt;/p&gt;&lt;/td&gt;
  </code></pre>
  
  <p><strong>INTENDED HTML:</strong></p>
  
  <pre><code>&lt;td align="center"&gt;line 1&lt;br /&gt;line 2&lt;br /&gt;line 3&lt;/td&gt;
  </code></pre>
  
  <p>Note that there are other <code>&lt;p&gt;...&lt;/p&gt;</code> tags throughout the HTML document that must not be touched. I only want to replace <code>&lt;p&gt;...&lt;/p&gt;</code> within a <code>&lt;td&gt;</code> or <code>&lt;th&gt;</code> only.</p>
  
  <p>I would also need a regexp to reverse the process. Please note that these regular expressions have to work in VB/VBScript/Classic ASP, so although I can use lookaheads (which I think is the key here), I cannot use lookbehinds. Some regex's I've tried unsuccessfully are:</p>
  
  <pre><code>1. &lt;td[^&gt;]*&gt;(&lt;p&gt;.+&lt;\/p&gt;)&lt;\/td&gt;
  2. &lt;td[^&gt;]*&gt;(&lt;p&gt;.+&lt;\/p&gt;)+?&lt;\/td&gt;
  3. &lt;td[^&gt;]*&gt;&lt;p&gt;(?:(.+?)&lt;\/p&gt;&lt;p&gt;(.+))+&lt;\/p&gt;&lt;\/td&gt;
  4. &lt;td[^&gt;]*&gt;(&lt;p&gt;(?:(?!&lt;\/p&gt;)).*&lt;\/p&gt;)+?&lt;\/td&gt;
  5. &lt;td[^&gt;]*&gt;(?:&lt;p&gt;(.+?)&lt;\/p&gt;)*(?:&lt;p&gt;(.+)&lt;\/p&gt;)&lt;\/td&gt;
  6. &lt;td[^&gt;]*&gt;(?:&lt;p&gt;(.+?)&lt;\/p&gt;)(?:&lt;p&gt;(.+)&lt;\/p&gt;)*(?:&lt;p&gt;(.+)&lt;\/p&gt;)&lt;\/td&gt;
  </code></pre>
  
  <p>I can "cheat" and pull out the entire line and then parse it manually usually standard VB string manipulation functions, but that's definitely not the most elegant, nor the fastest way. There has to be some way to do this in one shot using RegEx's.</p>
  
  <p>Eventually I'd like to take...</p>
  
  <pre><code>&lt;td align="center"&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;line 1&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;line 2&lt;/p&gt;&lt;p&gt;line 3&lt;/p&gt;&lt;/td&gt;
  </code></pre>
  
  <p>...and turn it into</p>
  
  <pre><code>&lt;td align="center"&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;line 1&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;line 2&lt;br /&gt;line 3&lt;/td&gt;
  </code></pre>
  
  <p>Any ideas (besides not to do this with a regex, lol)?</p>
  
  <p>Thank you!</p>