读书人

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

发布时间: 2013-03-28 10:20:24 作者: rapoo

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

读书人网 >C#

热点推荐