【发布时间】:2011-07-24 12:36:21
【问题描述】:
我有 matchCollection。 我需要组索引 1。 现在我从大量演员表中取出数据,我想避免它。
示例:startTag = <a>,endTag = </a>
html = <a>texttexttext</a>.
我需要得到没有<a> 和</a> 的“texttexttext”
var regex = new Regex(startTag + "(.*?)" + endTag, RegexOptions.IgnoreCase);
var matchCollection = regex.Matches(html);
foreach (var item in matchCollection)
{
string temp = ((Match)(((Group)(item)).Captures.SyncRoot)).Groups[1].Value;
}
【问题讨论】:
-
你知道正则表达式和 HTML/XML 是坏朋友,是吗?
-
@Marc Gravell,为什么?我不知道该怎么做
-
为什么要在这里使用 SyncRoot?
-
为什么stackoverflow.com/questions/1732348/… - HTML 敏捷包可能更好
-
您根本不能使用正则表达式解析 html。它将召唤旧神,给人类带来疯狂和毁灭:stackoverflow.com/questions/1732348/…