正则 群组 Group

  static void Main(string[] args)
        {
            string strUrl = "<a href=\"user.php?act=order_detail&order_id=425044\" target=\"_blank\" class=\"J_MakePoint status\">未付款</a> ";
            var s=GetHTOrderId(strUrl);
            //取到:order_id=425044
            Console.Read();
        }

        private static string GetHTOrderId(string linkUrl)
        {
            string pattern = "<a href=\"user.php?(?<A>.+?)&(?<orderID>.+?)\".*>(?<B>.+?)</a>";
            Regex rr = new Regex(pattern, RegexOptions.IgnoreCase);
            MatchCollection matches = rr.Matches(linkUrl);

            foreach (Match match in matches)
            {
                return match.Groups["orderID"].Value ;
            }
            return "";
        }

 

posted @ 2016-03-30 14:20  ChineseMoonGod  阅读(298)  评论(0)    收藏  举报