问个正则
字符串如下:
XXXXXCTP20A05 - [MealPlan Name:BKF,;MealPlan Count:2]XXXXXX[MealPlan Name:ABC,;MealPlan Count:5]XXXXXX
如何能匹配到Name为BKF中的2,其中2是整型。
------解决方案-------------------- string str = "XXXXXCTP20A05 - [MealPlan Name:BKF,;MealPlan Count:2]XXXXXX[MealPlan Name:ABC,;MealPlan Count:5]XXXXXX";
string name = "BKF";
int count = Convert.ToInt32((Regex.Match(str, string.Format(@"\[MealPlan Name:{0},;MealPlan Count:(\d+)\]",name)).Groups[1].Value));
//2
------解决方案--------------------------解决方案--------------------"Name为BKF中的2,其中2是整型" 实在理解不了
------解决方案--------------------(?<=\[MealPlan Name:BKF,;MealPlan Count:)\d+(?=\])