使用正则表达式获取TD标签的innerHTML

时间:2021-03-11 07:38:48

I want to parse HTML with regular expression. Here is the html source code:

我想用正则表达式解析HTML。这是html源代码:

<table border="1">
    <tr>
        <td>row 1, cell 1</td>
        <td>row 1, cell 2</td>
    </tr>
    <tr>
        <td>row 2, cell 1</td>
        <td>row 2, cell 2</td>
    </tr>
</table>

And I want to take innerHTML of TD tags in a collection.

我想在集合中使用TD标签的innerHTML。

PS: I don't know how many TD tags will be exist in the html source. I think this can be done with REGEX GROUPING. Please add explanations in your answer about grouping and your code.

PS:我不知道html源中会存在多少个TD标签。我认为这可以通过REGEX GROUPING完成。请在答案中添加有关分组和代码的说明。

Thanks in advance....

提前致谢....

1 个解决方案

#1


3  

Regex is a search tool, and is not suitable for parsing HTML (or any programming language for that matter) If you ever want to parse HTML HTML Agility Pack is probably the way to go.

Regex是一个搜索工具,不适合解析HTML(或任何编程语言)如果您想要解析HTML HTML Agility Pack可能就是这样。

#1


3  

Regex is a search tool, and is not suitable for parsing HTML (or any programming language for that matter) If you ever want to parse HTML HTML Agility Pack is probably the way to go.

Regex是一个搜索工具,不适合解析HTML(或任何编程语言)如果您想要解析HTML HTML Agility Pack可能就是这样。