Regex regOrg = new Regex(@"org(?:aniser)?\s+(\d\d):(\d\d)\s?(\d\d)?\.?(\d\d)?", RegexOptions.IgnoreCase);
MatchCollection mcOrg = regOrg.Matches(str);
Match mvOrg = regOrg.Match(str);
dayOrg = mvOrg.Value[4].ToString();
monthOrg = mvOrg.Value[5].ToString();
hourOrg = mvOrg.Value[2].ToString();
minuteOrg = mvOrg.Value[3].ToString();
这个正则表达式用文本分析字符串
"organiser 23:59" / "organiser 25:59 31.12"
或者
"org 23:59" / "org 23:59 31.12"
可选参数的日期和月份 因此,我想用这些数据查看输出变量 dayOrg、monthOrg、hourOrg、minuteOrg,但我得到了这个:
Query: org 23:59 31.12
The value mcOrg.Count: 1
The value dayOrg: 2
The value monthOrg: 3
The value hourOrg: g
The value minuteOrg: empty
我究竟做错了什么?尝试了很多选项,但它不起作用。