110,566
社区成员
发帖
与我相关
我的任务
分享
string html = @"<img src=""attchMap/A1424163916379259/20150217170415541.jpg"" border=""0""><div><img src=""AttchMap/A1424163916379957/20150217170426189.jpg"" border=""0"">\<br></div><div><img src=""AttchMap/A1424163916379857/20150217170435343.jpg"" border=""0""><br></div><div><table style=""table-layout: fixed; width: 759px; border-collapse: collapse; border-width: 1px 1px 0px; border-style: solid solid none; border-top-color: rgb(230, 230, 230); border-right-color: rgb(230, 230, 230); border-left-color: rgb(230, 230, 230); color: rgb(51, 51, 51); font-family: Arial; font-size: 12px; line-height: 18px;""><tbody><tr><th style=""margin: 0px; padding: 15px 0px 0px 20px; vertical-align: top; width: 118px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(230, 230, 230); font-size: 16px; line-height: 26px; font-family: 'Microsoft YaHei', arial; background-color: rgb(250, 250, 250);"">";
string patten = @"(?i)<img\s+.*?src=""(AttchMap[^""]*)""";
foreach (Match m in Regex.Matches(html, patten))
{
Console.WriteLine(m.Groups[1].Value);
}
这里没用RegexOptions.IgnoreCase枚举来指示不区分大小写,而是在正则中用了(?i)这种string patten=@"<img\s+.*?src=""(AttchMap[^""]*)""";
还少写了个双引号……string patten=@"<img\s+.*?src=""(AttchMap[^"]*)""";
安装VS2015过程中无法打开VS2013……蛋疼
匹配时正则选择忽略大小写,就不在里面写(?i)了,src取匹配到的match.Group[1].Value