using System; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { string pattern = @"\bError importing username: (\d+), primary email: ([^\s@]+@[^\s@,]+)"; string input = @"string error_message= ""{\""2705\"":\""Error importing username: 3167763, primary email: pkumar194@google.com, error: User already exists but Email does not match: pkumar194@googlee.com vs pkumar193@google.co.in\"",\""10001\"":\""Error importing username: 3195330, primary email: alejandra.mejia@google.com, error: User already exists but Email does not match: alejandra.mejia@google.com vs alejandra.mejia@googlee.com\""}"";"; var collection = Regex.Matches(input, pattern) .Cast() .Select(match => new {username = int.Parse(match.Groups[1].Value), primary_email = match.Groups[2].Value} ); foreach (var item in collection) { Console.WriteLine("username: {0}, primary email: {1}", item.username, item.primary_email ); } } }