大致意思是这样的:
1.我从数据库中提取新闻的内容字段出来,此处命名为nr。
2.由于采用了fckeditor控件,所以nr现在已经是html格式的内容了。
3.现在要将nr中出现的第一个img中的src读取出来,然后赋值给B。
nr的格式如下:
<img height="469" width="452" alt="" src="/UploadFile/FCKeditor/image/123.jpg" />
B的值应该是上面带下划线的值
请大家帮忙。。

解决方案 »

  1.   


      /// <summary>
            /// 获得图片的路径并存放
            /// </summary>
            /// <param name="M_Content">要检索的内容</param>
            /// <returns>IList</returns>
            public static IList<string> GetPicPath(string M_Content) 
            {
                IList<string> im = new List<string>();//定义一个泛型字符类
                Regex reg = new Regex(@"<img.*?src=""(?<src>[^""]*)""[^>]*>", RegexOptions.IgnoreCase);
                MatchCollection mc = reg.Matches(M_Content); //设定要查找的字符串
                foreach(Match m in mc)
                {
                    im.Add(m.Groups["src"].Value);
                }
                return im;
              
            }
      

  2.   


    B = Regex.Match(nr, "<img[^>]*src=[\"']*([^>\"']+)[\"']*\\s*/>").Groups[1].Value;
      

  3.   

    <img\s[^(src)]*\ssrc="([^"]*)" /> 
      

  4.   


    <img\s[^(src)]*\s*src="([^"]*)" /> 
    //这样稍微好点,还可以匹配只有src属性的情况。
      

  5.   

    不好吧,如果漏写了'"' scr=1.jpg  就比较危险了
      

  6.   

    static void Main(string[] args)
            {
                string str=@"<img height=""469"" width=""452"" alt="""" src=""/UploadFile/FCKeditor/image/123.jpg"" /> ";
                Regex re = new Regex(@"<img[^(src)]*src=""(?<src>[^""]*)""");
                Console.WriteLine(re.Match(str).Groups["src"].Value);        }
      

  7.   

    string pattern = "<IMG\\s+src=\"(?<src>[^\"]+?)\"[\\s\\S]*?>";
    Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
    MatchCollection m = r.Matches("");
    foreach(Match m in mc)
    {
          Console.WriteLine(mc.Groups["src"].Value);
    }
      

  8.   

    C#测试过。没问题的:
           string regexstr = "<img[\\s\\w\"=]+?(?<=src=\")(?<imgsrc>[/\\w\\.]+)(?=\")";
           Regex.Match(s, regexstr).Groups["imgsrc"].Value的值即为需要的字符串。
      

  9.   

    http://unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm#mission
      

  10.   


    string input = @"<img height=""469"" width=""452"" alt="""" src=""/UploadFile/FCKeditor/image/123.jpg"" /> ";
    Match m = Regex.Match(input, @"(?i)(?<=<img\b[^<>]*src\s*=\s*[""])[^""]*");
    string b = m.Value;
      

  11.   

    害人不浅阿
    [^(src)]* 的意思是除了左右括号、s、r、c五个字符外的任意个任意字符 这里之所以能匹配是碰巧了src前面没有这五个字符而已
    这样吧@"<img\s(?:(?!src)[^<>])*src=""([^""]*)""/>"
    取Groups[1].Value
      

  12.   

    [^(src)]* 的意思是除了左右括号、s、r、c五个字符外的任意个任意字符 这里之所以能匹配是碰巧了src前面没有这五个字符而已 ---------------
    额,是哦,
    (?:(?!src)[^<>])*