C# 字符串截取 求助
C# 字符串截取 求助
字符串如下:
string source = "abc{d[{ee},{ff},{gg}]hi}";
需要得到的结果信息 string[] s = {{ee},{ff},{gg}} ;
得到这样最好 list<string> ss = new list<string>{{ee},{ff},{gg}};
求简单代码
C#
String
正则表达式
------解决方案-------------------- string source = "abc{d[{ee},{ff},{gg}]hi}";
List<string> ss = new List<string>();
foreach (Match m in Regex.Matches(source, @"\{\w+\}"))
{
ss.Add(m.Value);
}
------解决方案--------------------try...
List<string> list = new List<string>();
string source = "abc{d[{ee},{ff},{gg}]hi} xyz{w[{vv},{uu},{tt}]rss}qqq";
Regex reg = new Regex(@"\{(?>[^{}]+
------解决方案--------------------
\{(?<o>)
------解决方案--------------------
\}(?<-o>))*(?(o)(?!))\}");
MatchCollection mc = reg.Matches(source);
foreach (Match m in mc)
{
list.Add(m.Value);
}