Declare an integer variable, increment it each time that you find a <table> tag, decrement when you find a </table>. Only output a <br> if the variable is zero. This will correctly handle nested tables. Depending on the source of your HTML, you may need to ensure that <TABLE> is also handled - HTML is not case sensitive so your code should not be either.
Incidentally, you example seems to have <br/> rather than <br>. HTH John ----- Original Message ----- From: "Vidar Langberget" <[EMAIL PROTECTED]> Sent: Friday, January 16, 2004 4:22 PM I know how to parse carriage returns and replace it with <br>, but I need a bit more advanced logic. The problem is that the text I need to parse contains both carriage returns and some basic html. For example headings use <h2>Heading</h2> and there are a few html tables as well. The tables are the biggest problem. The replace method I've written puts <br> several places inside the table html code, so it looks horrible in a browser. This is a small example: <table cellpadding="2" align="Center"><br/> <tbody><br/> <tr valign="Top"><br/> <td valign="Top"><br/> <div align="Left"> <h6> Architecture:</h6><br/> </div><br/> </td><br/> <td valign="Top"><h6> K7</h6><br/> </td><br/> <td valign="Top"><h6> P6</h6><br/> </td><br/> </tr><br/> <tr valign="Top"><br/> <td valign="Top"><p><b> Cache block size:</b></p><br/> </td><br/> <td valign="Top"><p> 64 Bytes<br/> </td><br/> <td valign="Top"><p> 32 Bytes<br/> </td><br/> </tr><br> As you can imagine I need to improve my parsing method to skip adding <br> inside <table and </table>. Any idea how I can do this? Also, the heading is a problem. The whole text is put inside <p></p> and it works as long as there is no html in the text. But after a heading using <h2> for example, the rest of the text is rendered using standard text as defined in the browser, and not as <p> is defined in my stylesheet. What I need to do is add a <p> tag to the text after a blank line UNLESS the next line is a heading. Suggestions on how to handle this? Any help appreciated! =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant archives, FAQs and Forums on JSPs can be found at: http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com