I try to split a string in C#.
Example1: "( Nr:1234 ) and ( Name:Test )"
Example2: "( Nr:1234 ) or ( Name:Test ) or ( Nr:456 ) or ( Name:A* )"
I need the strings inside of the brackets like f.e. "Nr:1234" or "Name:Test" into an array or a list of strings. There is always a space after the opening and before the closing bracket and before/after or respectively and.
I have tried this:
Regex r = new Regex(@"\((.*?)\)");
MatchCollection matches = r.Matches(sSearchString);
var list = matches.Cast<Match>().Select(match => match.Value).ToList();
But sometimes it is possible that the name also contains brackets, f.e. like this:
"( Name:This is a test (number one) ) or ( Nr:234 )"