110,533
社区成员
发帖
与我相关
我的任务
分享
string sss = "<img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" />";
string pattern = "<img.*title=\"(?<Title>.+?)\".*src=\"(?<SRC>.+?)\".*longdesc=\"(?<DESC>.+?)\" />";
string title = string.Empty;
string src = string.Empty;
string longdesc = string.Empty;
StringBuilder js = new StringBuilder();
Regex rr = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rr.Matches(sss);
int i = 1;
foreach (Match match in matches)
{
title = match.Groups["Title"].Value;
src = match.Groups["SRC"].Value;
longdesc = match.Groups["DESC"].Value;
js.Append("<li>");
js.Append("<a href=\"javascript:void(0);\">");
js.Append("<img src=\"\" width=\"120\" height=\"80\" alt=\"" + title + "\" />");
js.Append("</a>");
js.Append("</li>");
i++;
}
Console.Write(matches.Count.ToString());
Console.Write(js.ToString());
string sss = "<img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" />";
string pattern = @"<img[^>]*title=\""(?<title>[^""]*)\""[^>]*src=\""(?<src>[^""]*)\""[^>]*longdesc=\""(?<longdesc>[^""]*)";
string title = string.Empty;
string src = string.Empty;
string longdesc = string.Empty;
StringBuilder js = new StringBuilder();
Regex rr = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rr.Matches(sss);
int i = 1;
foreach (Match match in matches)
{
title = match.Groups["Title"].Value;
src = match.Groups["SRC"].Value;
longdesc = match.Groups["DESC"].Value;
js.Append("<li>");
js.Append("<a href=\"javascript:void(0);\">");
js.Append("<img src=\"\" width=\"120\" height=\"80\" alt=\"" + title + "\" />");
js.Append("</a>");
js.Append("</li>");
i++;
}
我这里是可以的
string pattern = "<img.*?title=\"(?<Title>.+?)\".*?src=\"(?<SRC>.+?)\".*?longdesc=\"(?<DESC>.+?)\" />";
应该是 .*?
<img[^>]*title=\\"(?<title>[^"]*)\\"[^>]*src=\\"(?<src>[^"]*)\\"