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

来源:互联网 发布:常州地球人软件 编辑:程序博客网 时间:2024/06/05 20:36

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

 

            Regex reg = newRegex(@"(?imn)(?<do>http://[^/]+/)(?<dir>([^/]+/)*([^/.]*$)?)((?<page>[^?.]+\.[^?]+)\?)?(?<par>.*$)");

            MatchCollection mc = reg.Matches(str);

            foreach (Match min 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();

原创粉丝点击