Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to parse following using regular expression? Every time it is going only upto the first </tr> of the inner table only, but i want it to loop through the inner table and end it at OUTER table's </tr>, i.e including all the text between those two <tr> , the nested table,too.
<tr>
 <td> ... </td>
 <td> ... </td>
 .
 .
 .
 <table>
    <tr>
      <td> ... </td>
    </tr>  <--- IT ENDS HERE
 </table>
 .
 .
 .
</tr>  <--- INSTEAD OF HERE




Posted

1 solution

Rule one: don't try to parse HTML with a regex, it will all end in tears...

Try this: HTML Agility pack[^] - a .NET HTML parser.
 
Share this answer
 
Comments
Dan Suthar 5-Jun-11 13:48pm    
ya thanks,.. Even I came across your rule one many times before. but html here is just i used to give an example. In general it's just a text with nested sub elements of same kind. Then what should i do?
OriginalGriff 5-Jun-11 13:52pm    
Still don't use a regex :laugh: - it will very quickly get too complex and unmanageable! Remember that you will have to maintain this code in three months time when they change the spec...
Dan Suthar 5-Jun-11 13:53pm    
hmmm,,that's also true ..
Kim Togo 5-Jun-11 14:38pm    
My 5 for not recommending RegEx for HTML.
Wonde Tadesse 5-Jun-11 16:39pm    
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900