正则匹配指定位置数字

来源:互联网 发布:linux 专家编程 pdf 编辑:程序博客网 时间:2024/05/19 12:40
                string coup = dt.Rows[i]["CouponInfo"].ToString();                Regex r = new Regex("满(\\d+)元减\\d+元", RegexOptions.IgnoreCase);                Match m = r.Match(coup);                if (m.Success)                {                    tkcoupon.CouponInfo = m.Result("$1");                }
方法二
                 string coup = dt.Rows[i]["CouponInfo"].ToString();Match m= Regex.Match(coup, "满(\\d+)元减\\d+元", RegexOptions.IgnoreCase);tkcoupon.CouponInfo = m.Result("$1");
写成一行
 tkcoupon.CouponInfo = Regex.Match(dt.Rows[i]["CouponInfo"].ToString(), "满(\\d+)元减\\d+元", RegexOptions.IgnoreCase).Result("$1");