求助一个正则表达式(C#),将1111.txt这个文件名取出来
http://localhost:3766/filedownload?s=Files%5c642&p=1&f=11222&o=1111.txt&pr=d
正则表达式C#

解决方案 »

  1.   

    (?is)(?<=(&o=)).*(?=(&))
      

  2.   

                string test1 = "http://localhost:3766/filedownload?s=Files%5c642&p=1&f=11222&o=1111.txt&pr=d";
                string test2 = "http://localhost:3766/filedownload?s=Files%5c642&p=1&f=11222&pr=d&o=1111.txt";            Regex regex = new Regex(".*o=(?<o>[^&]*).*");
                
                Match m1 = regex.Match(test1);
                Match m2 = regex.Match(test2);            Console.WriteLine(m1.Groups["o"].Value);
                Console.WriteLine(m2.Groups["o"].Value);
      

  3.   

    string filename = "http://localhost:3766/filedownload?s=Files%5c642&p=1&f=11222&o=1111.txt&pr=d".split('&')[2]
      

  4.   

     string patten="&o=([^&]*)&";
      

  5.   

    原来是为了以后的拓展
                string urlstr = "http://localhost:3766/filedownload?s=Files%5c642&p=1&f=11222&o=1111.txt&pr=d";
                var filenames = urlstr.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(x => x.Split('=')[0], p => p.Split('=')[1]);
                Console.WriteLine(filenames["o"]);
                Console.Read();