It looks like your input line is a JSON line for which you can use the JSON deserializer if you want. If not, you can use the regex with named groups as follows:
List<string> values = new List<string>(); List<string> keys= new List<string>(); string pattern = @"\""(?<key>[^\""]+)\""\:\""?(?<value>[^\"",}]+)\""?\,?"; foreach(Match m in Regex.Matches(input, pattern)) { if (m.Success) { values.Add(m.Groups["value"].Value); keys.Add(m.Groups["key"].Value); } } var result = values.ToArray();
Named groups in the regular expression are indicated by the symbol (?<group-name>pattern) . In the above template, we have two named groups: key and value , which can be captured from the Match object using the Groups indexer.
source share