How can I take the string foo[]=1&foo[]=5&foo[]=2 and return a collection with the values 1,5,2 in that order. I am looking for an answer using
foo[]=1&foo[]=5&foo[]=2
1,5,2
In C# you can use capturing groups
private void RegexTest() { String input = "foo[]=1&foo[]=5&foo[]=2"; String pattern = @"foo\[\]=(\d+)"; Regex regex = new Regex(pattern); foreach (Match match in regex.Matches(input)) { Console.Out.WriteLine(match.Groups[1]); } }