日期:2014-05-18 浏览次数:20794 次
string tstr = "{第一中学}{一年级}{数学}{{张三}{李四}}{{89}{92}}"; //Regex reg = new Regex(@"\{[^\{\}]* ( ( (?'Open'\{)[^\{\}]* )+ ( (?'-Open'\})[^\{\}]* )+ )* (?(Open)(?!)) \}"); //Regex reg = new Regex(@"\{[^{}]*\}"); Regex reg = new Regex(@"\{[^{}]*(((?'Open'{)[^{}]*)+((?'-Open'})[^{}]*)+)*(?(Open)(?!))\}"); string text = ""; MatchCollection mc = reg.Matches(tstr); foreach (Match m in mc) { Console.WriteLine(m.Value); } Console.ReadLine();