正则表达式达人请进

moonwrite 2015-07-22 10:08:43
<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);">

找出 img src="AttchMap....." 开头的正则,忽略大小写
要的只是 src="只要这里面的"
谢谢
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
瑞卡哥哥 2015-07-23
  • 打赏
  • 举报
回复
src=\"([^"]*)\"
  • 打赏
  • 举报
回复
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

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧