I typically have a string that might look like the following and I would like to extract the contents and parse it into an array by splitting the values.
COUNT(123,453,123)
For validation reasons it might so happen that a comma is left on the end of contents like so.
COUNT(123,453,123,)
My code so far is as follows.
Regex.Match(testString, @"(?<=\().+?(?=\))").ToString().Split(',').Select(int.Parse).ToList();
It works fine for the first case but will throw an exception on the latter case.
Exception
input string was not in a correct format
How can I make the regex ignore a comma if there is no additional number after it?