【发布时间】:2021-12-14 17:13:46
【问题描述】:
我正在尝试使用正则表达式进行模式匹配。如果消息在模式字符串后有空格,则得到一个空字符串。
string str = "studentId: 1234, Name: Hello";
Regex reg = new Regex(@"studentId:(\d*)", RegexOptions.IgnoreCase);
Match m = reg.Match(str);
Group g = m.Groups[1];
int Id = int.Parse(g.ToString());
studentId:1234(工作) 学生 ID:1234(不工作) studentId:1234(不工作)
我需要得到 1234 的值而不考虑空格。
【问题讨论】: