He is looking for {...} with some (1 or more) non-} inside. If successful, it places the contents of {...} in capture group 1.
Regex x = new Regex("{([^}]+)}"); var m = x.Match("{Hello}"); string str0 = m.Groups[0].ToString();
Group 0 always matches everything.
var m2 = x.Match("{}"); var success = m2.Success;
It is not bound, so it can have more than one match for each row ...
var m2 = x.Matches("{Hello}{}{World}"); int c = m2.Count;
As a side element, if you think this is the beginning for a good C # parser, you are on the wrong track :-) Expressions like { { string str = "Hello"; } str += "x"; } { { string str = "Hello"; } str += "x"; } { { string str = "Hello"; } str += "x"; } will confuse this regular expression, therefore expressions like { string str = "}" } . This is an irregular regular expression. No fancy tricks.
source share