首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

正则的求解,提取html中的内容解决方法

2013-03-28 
正则的求解,提取html中的内容div classcontent title2013-03-26 12:00:42我需要的内容/div正htm

正则的求解,提取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>)";

热点排行