-1

我一直在 MSDN 上阅读 .NET 中的正则表达式,但我无法弄清楚正确的模式是什么。我需要从 HTML 文件中提取 'width="200" height="200" />'。我需要引号。我应该使用什么正确的模式?

4

1 回答 1

1

Given a specific HTML page, you can craft a regex that can pull the attributes for that page. But if you have only one specific page, you can just hard-code its attribute values. But you probably want to be able to pull the attribute values from any page, right? You can't do that with regular expressions. Really, you can't, and trying to do so will lead you into an infinite loop of failure.

Use the HTML Agility Pack; it's designed to do exactly what you asked; even with ill-formed real-world HTML.

于 2013-07-09T00:36:08.660 回答