本帖最后由 jasonliangbiz 于 2010-05-23 11:18:00 编辑

解决方案 »

  1.   

    src="(?'url'/UpFiles/[^"]*)"结果是一个数组,如果中间要加|||的话,可以用for循环了去加上去.
      

  2.   

    try...            Regex reg = new Regex(@"(?i)<img[^>]*?\ssrc=(['""]?)(?<src>/UpFiles/[^'""\s>]+)\1[^>]*>");
                MatchCollection mc = reg.Matches(yourStr);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Groups["src"].Value + "\n";
                }
      

  3.   

    这个匹配后连http://www.163.com/UpFiles/sy/444.jpg" />中的/UpFiles/sy/444.jpg也匹配上去了.
    不需要匹配这个.
    谢谢kkbac
      

  4.   


    经测试,我这个不匹配http://www.163.com/UpFiles/sy/444.jpg
      

  5.   


    忽略大小写,在.NET中等价于RegexOptions.IgnoreCase
      

  6.   

    哈哈,学习了.
    如果我想匹配111.jpg  222.jpg   333.jpg
    也就是把原来匹配的去掉前面部分.只留图片的文件名.
    又如何写呢?
      

  7.   

    try...           Regex reg = new Regex(@"(?i)<img[^>]*?\ssrc=(['""]?)/UpFiles/([^'""\s>/]*/)*(?<name>[^'""\s>.]+\.[^'""\s>]+)\1[^>]*>");
                MatchCollection mc = reg.Matches(yourStr);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Groups["name"].Value + "\n";
                }
      

  8.   

    new regex(@"....", RegexOptions.Singleline);试试.
      

  9.   

    给下你的测试代码            string test = @"
    <img onload=javascript:DrawImage(this);  alt='111'  height=""640""  width=""480"" border=""0"" src=""/UpFiles/sy/111.jpg"" />
    <img onload=javascript:DrawImage(this);  alt='222'  height=""640""  width=""480"" border=""0"" src=""/UpFiles/sy/222.jpg"" />
    <img onload=javascript:DrawImage(this);  alt='333'  height=""640""  width=""480"" border=""0"" src=""/UpFiles/sy/333.jpg"" />
    <img onload=javascript:DrawImage(this);  alt='444'  height=""450""  width=""600"" border=""0"" src=""http://www.163.com/UpFiles/sy/444.jpg"" />
    <img onload=javascript:DrawImage(this);  alt='555'  height=""640""  width=""480"" border=""0"" src=""http://www.163.com/UpFiles/sy/UpFiles/sy/555.jpg"" />
    ";
                Regex reg = new Regex(@"(?i)<img[^>]*?\ssrc=(['""]?)/UpFiles/([^'""\s>/]*/)*(?<name>[^'""\s>.]+\.[^'""\s>]+)\1[^>]*>");
                MatchCollection mc = reg.Matches(test);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Groups["name"].Value + "\n";
                }
    /*-------输出---------
    111.jpg
    222.jpg
    333.jpg
    */
      

  10.   

    哈哈.可以了.原来是我这里 m.Groups["src"].Value
    应该是m.Groups["name"].Value + "\n";
    非常感谢!