如何用正则匹配"嵌套"类型的,得出想要的结果? 代码:{第一层{第二层}}用正则后想取得两个数据.1,第一层{第二层}2,第二层如何写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str = @"{第一层{第二层}}"; Match m = new Regex(@"(?<=\{)[^{}]+(?:(?:(?<Open>\{)([^{}]+))*(?:(?<-Open>\})[^{}]*)*)*(?=\})").Match(str); Console.WriteLine(m.Value); foreach (Capture c in m.Groups[1].Captures) Console.WriteLine(c.Value);/*第一层{第二层}第二层*/ string r1 = Regex.Replace(s, @"^\s*{|}\s*$", ""); string r2 = Regex.Match(s, @"{([^{}]+)}").Groups[1].Value; static Regex reg = new Regex(@"(?<=\{)[^{}]+((?:(?<Open>\{)(?:[^{}]+))*(?:(?<-Open>\})[^{}]*)*)*(?=\})"); static void Main(string[] args) { string str = @"{第一层{第二层{第三层{第四层}}}}"; GetValue(str); Console.ReadKey(); } public static void GetValue(string str) { Match m = reg.Match(str); if (m.Success) { Console.WriteLine(m.Value); GetValue(m.Value); } }/*第一层{第二层{第三层{第四层}}}第二层{第三层{第四层}}第三层{第四层}第四层*/ static Regex reg = new Regex(@"(?<=\{)[^{}]+((?:(?<Open>\{)(?:[^{}]+))*(?:(?<-Open>\})[^{}]*)*)*(?=\})"); static void Main(string[] args) { string str = @"{第一层{第二层{第三层{第四层{第五层{第六层}}}}}}"; GetValue(str); Console.ReadKey(); } public static void GetValue(string str) { Match m = reg.Match(str); if (m.Success) { Console.WriteLine(m.Value); GetValue(m.Value); } }/*第一层{第二层{第三层{第四层{第五层{第六层}}}}}第二层{第三层{第四层{第五层{第六层}}}}第三层{第四层{第五层{第六层}}}第四层{第五层{第六层}}第五层{第六层}第六层*/ 请教用户登录时的数据库操作,怎样写SQLScript比较好? 急!急!asp.net vb GridView第五列减第6列等于第七列 怎么做 下面这句话怎么理解啊 Jquery表单验证的奇怪问题 网站的权限设置 急!ado.net写入数据变成乱码 有关.NET调用DLL版本不对的问题. 高手指点,SSL的问题 用正则表达试如何找到2个字符串的相同部分? .net经常出现“Base-64 字符数组的无效长度。” asp.net一个int+0000怎么得到0001这种数 类似于QQ空间的空间是如何实现的?asp.net
string str = @"{
第一层
{
第二层
}
}
";
Match m = new Regex(@"(?<=\{)[^{}]+(?:(?:(?<Open>\{)([^{}]+))*(?:(?<-Open>\})[^{}]*)*)*(?=\})").Match(str);
Console.WriteLine(m.Value);
foreach (Capture c in m.Groups[1].Captures)
Console.WriteLine(c.Value);
/*第一层
{
第二层
}
第二层
*/
string r1 = Regex.Replace(s, @"^\s*{|}\s*$", "");
string r2 = Regex.Match(s, @"{([^{}]+)}").Groups[1].Value;
static void Main(string[] args)
{
string str = @"{
第一层
{
第二层
{
第三层
{
第四层
}
}
}
}
";
GetValue(str);
Console.ReadKey();
}
public static void GetValue(string str)
{
Match m = reg.Match(str);
if (m.Success)
{
Console.WriteLine(m.Value);
GetValue(m.Value);
}
}
/*第一层
{
第二层
{
第三层
{
第四层
}
}
}
第二层
{
第三层
{
第四层
}
}
第三层
{
第四层
}
第四层
*/
static Regex reg = new Regex(@"(?<=\{)[^{}]+((?:(?<Open>\{)(?:[^{}]+))*(?:(?<-Open>\})[^{}]*)*)*(?=\})");
static void Main(string[] args)
{
string str = @"{
第一层
{
第二层
{
第三层
{
第四层
{
第五层
{
第六层
}
}
}
}
}
}
";
GetValue(str);
Console.ReadKey();
}
public static void GetValue(string str)
{
Match m = reg.Match(str);
if (m.Success)
{
Console.WriteLine(m.Value);
GetValue(m.Value);
}
}
/*
第一层
{
第二层
{
第三层
{
第四层
{
第五层
{
第六层
}
}
}
}
}第二层
{
第三层
{
第四层
{
第五层
{
第六层
}
}
}
}第三层
{
第四层
{
第五层
{
第六层
}
}
}第四层
{
第五层
{
第六层
}
}第五层
{
第六层
}第六层
*/