62,268
社区成员
发帖
与我相关
我的任务
分享
//用平衡组来实现
string str = "{0123{0165}},{4567{890-}}";
Regex reg = new Regex(@"{[^{}]*(((?<Open>{)[^{}]*)+((?<-Open>})[^{}]*)+)*(?(Open)(?!))}");
foreach (Match m in reg.Matches(str))
{
Response.Write(m.Groups[1].Value + "===" + m.Value + "<br/>");
}
/*
{0165}==={0123{0165}}
{890-}==={4567{890-}}
*/
@"(?x)
{
[^{}]*
(
( (?'k'{) [^{}]* )+
( (?'-k'}) [^{}]* )+
)*
(?(k)(?!))
}"
static void Main(string[] args)
{
string html = @"...";
MatchCollection mc = Regex.Matches(html, @"{[^{}]+}");
{
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
}
Console.ReadKey();
}
string inputString = "{0在123{05w中35}}{04的有有56{0在wr不是辊 78}}";
MatchCollection mc = new Regex(@"{[^{}]+({[^}]+})}").Matches(inputString);
foreach (Match m in mc)
Console.WriteLine(m.Groups[1].Value + "\t" + m.Groups[0].Value);
string inputString = "{0123{0165}}{0456{0678}}";
MatchCollection mc = new Regex(@"(?<={)(\d+){(\d+)}(?=})").Matches(inputString);
foreach (Match m in mc)
Response.Write(m.Groups[2].Value + " " + m.Groups[1].Value + "<br />");
/*
0165 0123
0678 0456
*/
