Q:

Need help for c# Regex

I'm trying to create a Regex with named groups that matches all of the four following strings:
var club = "Real Madrid";
var city = "Madrid";
var nation = "Spain";

var string1 = club;
var string2 = club + "," + city;
var string3 = club + "(" + nation + ")";
var string4 = club + "," + city + "(" + nation + ")";

Or in other words:
String looks like "club,city(nation)" where city and nation are optional with optional whitespaces included.
Thanks for any help!

A:

Regex from aelor but added a "(" sign after "^(?[^," to match the string "Real Madrid(Spain)"
Added a code example too.
var strings = new List<string>() { "Real Madrid", "Real Madrid,Madrid", "Real Madrid(Spain)", "Real Madrid,Madrid(Spain)" };

foreach (var str in strings)
{
    var match = Regex.Match(str, @"^(?<club>[^,]+)(?:,(?<city>[^\(]+))?(?:\((?<nation>[^\)]+)\))?$");

    var name = match.Groups["club"].Value;
    var city = match.Groups["city"].Value;
    var country = match.Groups["nation"].Value;
}

