System.Text.RegularExpressions.Regex r =new System.Text.RegularExpressions.Regex(@"<http(.|\n)+jpg?>");
foreach(System.Text.RegularExpressions.Match m in r.Matches(s))
{
//this.Save(m.Value);
System.Console.WriteLine(m.Value);

}
为什么不匹配呢
http://hs2.hnol.net/bbsimg/2006-3-28/17/200632817301761050.jpg

解决方案 »

  1.   

    不知道你拿来做什么用的,如果是要匹配jpg图片的地址,写成:
    new Regex(@"^http.+\.jpg$")
      

  2.   

    foreach(System.Text.RegularExpressions.Match m in r.Matches(s)){}中 s 是怎么定义的??学习中
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;//需加
    using System.IO;//需加
    using System.Text.RegularExpressions;
    namespace thief
    {
        class Program
        {
            static void Main(string[] args)
            {            try
                {
                    WebClient MyWebClient = new WebClient();                MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。                byte[] pageData = MyWebClient.DownloadData("http://www.backchina.org/main/showthread.php?tid=482390&extra=page%3D1");//从指定网站下载数据
                    string pageHtml = Encoding.UTF8.GetString(pageData);
                    Regex r = new Regex(@"^http.+\.jpg$");
                    foreach (Match m in r.Matches(pageHtml))
                    {                    Console.WriteLine(m.Value);           //this.Save(m.Value);
                        using (StreamWriter sw = new StreamWriter("d:\\ouput.html"))//将获取的内容写入文本
                        {
                            sw.Write(m.Value);
                        }
                    }                Console.WriteLine("下载成功"); //让控制台暂停,否则一闪而过了               
                }            catch (WebException webEx)
                {
                    Console.WriteLine(webEx.Message.ToString());
                }
            }
        }
    }
    为什么调试成功却没有出现写入的文件????