正则匹配指定位置数字
方法一:
1string coup = dt.Rows[i]["CouponInfo"].ToString();
2
3 Regex r = new Regex("满(\\d+)元减\\d+元", RegexOptions.IgnoreCase);
4 Match m = r.Match(coup);
5 if (m.Success)
6 {
7 tkcoupon.CouponInfo = m.Result("$1");
8 }
方法二:
1string coup = dt.Rows[i]["CouponInfo"].ToString();
2 Match m= Regex.Match(coup, "满(\\d+)元减\\d+元", RegexOptions.IgnoreCase);
3 tkcoupon.CouponInfo = m.Result("$1");
写成一行
1tkcoupon.CouponInfo = Regex.Match(dt.Rows[i]["CouponInfo"].ToString(), "满(\\d+)元减\\d+元", RegexOptions.IgnoreCase).Result("$1");