日期:2014-05-17  浏览次数:20670 次

正则的求解,提取html中的内容
<div class="content" title="2013-03-26 12:00:42">我需要的内容</div>


正html 是很长的。有很多组div内容我需要全部取出。

            Regex regImg = new Regex(@"<div class=""content"" title="".*"">?<imgUrl>(.*)</div>", RegexOptions.IgnoreCase);
            // 搜索匹配的字符串sHtmlText 为html内容
            MatchCollection matches = regImg.Matches(sHtmlText);

            int i = 0;
            string[] sUrlList = new string[matches.Count];

            // 取得匹配项列表
            foreach (Match match in matches)
                sUrlList[i++] = match.Groups["imgUrl"].Value;

            return sUrlList;

我这样写错了。求指导。
html 正则 提取内容

------解决方案--------------------
"(?is)(?<=<div[^<>]>)[^<>]+(?</div>)"
------解决方案--------------------
变量=[\s\S]*?
------解决方案--------------------
内容=(?<TARGET>[\s\S]+)
------解决方案--------------------
string pattern=@"(?<=<div[^>]*?class=""content""[^>]*?>).*?(?=</div>)";