在C#應用程序中,我希望將每個HTML「字體」標籤與「顏色」屬性匹配。匹配嵌套的HTML標籤
我有以下文字:
1<font color="red">2<font color="blue">3</font>4</font>56
而且我要包含以下項目一MatchCollection:
[0] <font color="red">234</font>
[1] <font color="blue">3</font>
但是,當我使用此代碼:
Regex.Matches(result, "<font color=\"(.*)\">(.*)</font>");
的MatchCollection我得到的是以下內容:
[0] <font color="red">2<font color="blue">3</font>4</font>
如何獲得我想用C#的MatchCollection?
謝謝。
你的正則表達式匹配任何東西,一切都變成一個組。你應該知道正則表達式對嵌套的東西不是很好。用HtmlAgilityPack之類的東西解析它會讓你更容易(更清潔)。 –
您應該改用HtmlAgilityPack。 http://htmlagilitypack.codeplex.com – Matthew
謝謝!我會嘗試! :P – anpep