Reputation: 87
I have the following html contained in a string.
<tr>
<td>Hello</td>
</tr>
<tr>
<td>World</td>
</tr>
<tr>
<td>lets all smile</td>
</tr>
I would like to use RegEx to find the <tr></tr> that contains the text "World". The difficulty is that there might be other <td> around the one that contains the search text. So we need to be able to search for the <tr> and </tr> nearest to the search text with any text between the <tr> and the search text.
The result of the match would be.
<tr>
<td>World</td>
</tr>
I'm using vb.net by the way.
Could anyone help at all?
Thanks
Richard
Upvotes: 0
Views: 689
Reputation: 129782
First of all, it should be pointed out that you want to use the HTML Agility Pack, and not regex, for this kind of things.
But other than that, a pattern could look like:
(<tr>.*?World.*?</tr>)
It's a rather lousy pattern, but then again, use the agility pack.
Upvotes: 6