
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 1.22 KB | hits: 8 | expires: Never
Regex Named Capturing Groups in .NET - Regex Pattern
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;
string pattern = @"(?<Person>[w ]+) has been to (?<NumberOfGames>d+) bingo games. The last was on (?<Day>w+) (?<Date>dd/dd/d{4}). She won with the Numbers: (?<Numbers>.*?)$";
string title = match.Groups["Person"].Value;
string drawNumber = match.Groups["NumberOfGames"].Value;
string title = match.Groups["Person"].Value;
string drawNumber = match.Groups["NumberOfGames"].Value;
string pattern = @"(?<Person>w+?) has been to (?<NumberOfGames>d+?) bingo games. The last was on (?<Day>...?) (?<Date>d+/d+/d+). She won with the Numbers: (?<Numbers>...?)";