简体   繁体   English

正则表达式与vb.net

[英]Regex with vb.net

I have the following html contained in a string. 我在字符串中包含以下html。

<tr> <tr>
<td>Hello</td> <td>你好</ td>
</tr> </ tr>
<tr> <tr>
<td>World</td> <td>世界</ td>
</tr> </ tr>
<tr> <tr>
<td>lets all smile</td> <td>让所有的人微笑</ td>
</tr> </ tr>

I would like to use RegEx to find the <tr></tr> that contains the text "World". 我想使用RegEx查找包含文本“世界”的<tr> </ tr>。 The difficulty is that there might be other <td> around the one that contains the search text. 困难之处在于,包含搜索文本的内容周围可能还有其他<td>。 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. 因此,我们需要能够使用<tr>和搜索文本之间的任何文本来搜索最接近搜索文本的<tr>和</ tr>。

The result of the match would be. 匹配的结果将是。

<tr> <tr>
<td>World</td> <td>世界</ td>
</tr> </ tr>

I'm using vb.net by the way. 我正在使用vb.net。

Could anyone help at all? 有人可以帮忙吗?

Thanks 谢谢

Richard 理查德

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. 首先,应该指出,您想使用HTML Agility Pack而非正则表达式来进行此类操作。

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. 这是一个很糟糕的模式,但是再次使用敏捷包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM