string imglist = "13131<img src=\"/img/2012/12/22/1451061507.gif\" alt=\"\"/>dsdfsdf<img src=\"/img/2012/12/22/1451061508.gif\" alt=\"\"/>dsdfsdf<img src=\"/img/2012/12/22/1451061509.gif\" alt=\"\"/>dsdfsdf";
结果是:
------解决方案--------------------------------------------------------
string imglist = "13131<img src=\"1.gif\" alt=\"\"/>dsdfsdf<img src=\"2.gif\" alt=\"\"/>dsdfsdf<img src=\"3.gif\" alt=\"\"/>dsdfsdf";
var ary = Regex.Matches(imglist, @"src=""(\w+\.(gif
------解决方案--------------------------------------------------------
jpe?g
------解决方案--------------------------------------------------------
bmp
------解决方案--------------------------------------------------------
png))""").Cast<Match>().Select(t => t.Groups[1].Value).ToArray(); ;
------解决方案--------------------------------------------------------
var ary = Regex.Matches(imglist, @"src=""([^""]+?\.(gif
------解决方案--------------------------------------------------------
jpe?g
------解决方案--------------------------------------------------------
bmp
------解决方案--------------------------------------------------------
png))""").Cast<Match>().Select(t => t.Groups[1].Value).ToArray(); ;
------解决方案--------------------------------------------------------
Regex reg = new Regex(@"(?is)<img[^>]*?src=([""']?)(?<src>[^""'>\s]+)\1[^>]*>");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["src"].Value + "\n";
}
------解决方案--------------------------------------------------------
奉劝你一句,是用成熟的html语法分析器(甚至自己是用yacc、lex之类的开源类库),不要整什么半吊子的所谓“正则表达式”。
------解决方案--------------------------------------------------------
(?is)<img\s*src=(["'])?([^"']*?)\1\s*alt=""[^>]*?/>
Regex reg = new Regex(@"(?is)<img\s*src=([""'])?([^""']*?)\1\s*alt=""""[^>]*?/>");
MatchCollection mc = reg.Matches(yourStr);
string str="";
foreach (Match m in mc)
{