Prologue:
Input string: 1(2),3,4(5,6(7,8),9),10
I am using C# and I would want to eventually get a List<foo>
from the above expression
public class foo
{
public int bar { get; set; }
public List<foo> listOfFoo { get; set; }
}
I can achieve the task by writing some validations and parsing character by character, but would like to know a better way. Lesser the code, lesser the bugs they say ;)
Query
I am looking for a regular expression for validating and possibly capturing information in a string like
1(2),3,4(5,6(7,8),9),10
The string is basically a set of numbers separated by comma. But a number can have some sub expressions for it using parenthesis (
)
What I want to fetch from the string is a graph like
1
2
3
4
5
6
7
8
9
10
I have very little idea about reg-ex. I can read & understand most of them, but writing one I find really tough
Looking for someone to tell me if something like this is at all achievable using RegEx. If so, what should be the approach? I can see that I would need a recursive expression, any links or examples would be of great help. Someone willing to give me the RegEx itself would be icing on the cake :)