我正在努力使用一种正则表达式模式,该模式会将文本从字符串中提取到命名组中。
一个(有点武断的)示例将最好地解释我想要实现的目标。
string input =
"Mary Anne has been to 949 bingo games. The last was on Tue 24/04/2012. She won with the Numbers: 4, 6, 11, 16, 19, 27, 45";
string pattern =
@"(?<Person>\w+?) has been to (?<NumberOfGames>\d+?) bingo games. The last was on (?<Day>...?) (?<Date>...?). She won with the Numbers: (?<Numbers>...?)";
Regex regex = new Regex(pattern);
var match = regex.Match(input);
string person = match.Groups["Person"].Value;
string noOfGames = match.Groups["NumberOfGames"].Value;
string day = match.Groups["Day"].Value;
string date = match.Groups["Date"].Value;
string numbers = match.Groups["Numbers"].Value;
我似乎无法让正则表达式模式工作,但我认为上面解释得很好。基本上我需要得到人名,游戏数量等。
任何人都可以解决这个问题并解释他们制定的实际正则表达式模式吗?