C#正则截取URL网址字符串

复制代码
string str = "http://www.rczjp.cn/A/B/C/index.aspx?cid=11&sid=22";
 

            Regex reg = new Regex(@"(?imn)(?<do>http://[^/]+/)(?<dir>([^/]+/)*([^/.]*$)?)((?<page>[^?.]+\.[^?]+)\?)?(?<par>.*$)");
            MatchCollection mc = reg.Matches(str);
            foreach (Match m in mc)
            {
                Console.WriteLine(m.Groups["do"].Value);  //http://www.rczjp.cn/
                Console.WriteLine(m.Groups["dir"].Value); //A/B/C/
                Console.WriteLine(m.Groups["page"].Value);  //index.aspx
                Console.WriteLine(m.Groups["par"].Value); //cid=11&sid=22
            }
            Console.Read();
复制代码

 

posted on   HOT SUMMER  阅读(1881)  评论(0编辑  收藏  举报

< 2012年5月 >
29 30 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9

导航

统计

点击右上角即可分享
微信分享提示