<by_newstype Count="5"></by_newstype>以上这段html标签我可以用以下匹配出来public static List<string> GetTagList(string html)
{
List<string> list = new List<string>();
Regex rx = new Regex(@"<(by_\w+) .*?>[^<]*</\1>", RegexOptions.Multiline | RegexOptions.Singleline);
MatchCollection collection = rx.Matches(html);
for (int i = 0; i < collection.Count; i++)
{
var item = collection[i];
list.Add(item.Value);
}
return list;
}
可是如果出现嵌套的标签时候,上面的正则表达式只能匹配到最外层的标签,嵌套在里面的那个却无法匹配。<by_newstype Count="5"><by_news type_id="5"></by_news></by_newstype>
怎么做才能同时匹配到外层的标签和嵌套在里面的<by_news type_id="5"></by_news>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货