当前位置: 代码迷 >> ASP.NET >> 怎么在一段字符串中找出所有图片路径
  详细解决方案

怎么在一段字符串中找出所有图片路径

热度:286   发布时间:2013-02-25 00:00:00.0
如何在一段字符串中找出所有图片路径
砌砖工人苦<img alt="121" src="/uploadfiles/images/editor/image/20120315/20120315004224_9246.jpg" />这里是新闻内容,东奔西走东奔西走东奔西走。<img alt="" src="/uploadfiles/images/editor/image/20120315/20120315004228_2246.jpg" />塔顶云蒸霞蔚裁夺工......

现在需要取出:/uploadfiles/images/editor/image/20120315/20120315004224_9246.jpg 和
/uploadfiles/images/editor/image/20120315/20120315004228_2246.jpg


用正则应该是很好弄的。可惜我是正则白痴。

------解决方案--------------------------------------------------------
探讨

C# code

string patern = @"(?is)<img\b[^<>]*?\bsrc\s*=""(?<url>(.*?))""[^<>]*?/?\s*>";
Match m = Regex.Match(s, patern);
for (int i = 1; i < m.Groups.Count; i++)
……
  相关解决方案