I had a slightly different requirement: for parsing an encoded dictionary / hash table with escaped commas, for example:
"1=This is something, 2=This is something,,with an escaped comma, 3=This is something else"
I think this is a nifty solution with a trick that avoids the complexity of regex:
if (string.IsNullOrEmpty(encodedValues)) { return null; } else { var retVal = new Dictionary<int, string>(); var reFields = new Regex(@"([0-9]+)\=(([A-Za-z0-9\s]|(,,))+),"); foreach (Match match in reFields.Matches(encodedValues + ",")) { var id = match.Groups[1].Value; var value = match.Groups[2].Value; retVal[int.Parse(id)] = value.Replace(",,", ","); } return retVal; }
I think it can be adapted to the original question with an expression like @"([0-9]+),\s?" and parse into Groups[0] .
I hope this helps someone and thanks for the tips on how to approach him, especially Asaf!
alpsystems.com Jun 06 2018-12-06T00: 00Z
source share