比较难的正则,大侠帮忙呀!谢过了

Jackie 2008-04-16 03:17:28
({result: ("A":{1,2,3}, "B":{4,5,6}, "C":{7,8,9}, total:26)})

取其中的"A":{1,2,3}、"B":{4,5,6}、"C":{7,8,9}等这个group,如何写正则表达式?
...全文
48 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hackztx 2008-04-17
  • 打赏
  • 举报
回复

using System;

using System.Text.RegularExpressions;

public class Test
{
static void Main(string[] args)
{
string str = @"({result: (""A"":{1,2,3}, ""B"":{4,5,6}, ""C"":{7,8,9}, total:26)})";

MatchCollection mc = Regex.Matches(str, @"""[A-Z].*?}");
int count = mc.Count;
if (count > 0)
{
Console.WriteLine("存在数据");
for (int i = 0; i < count; i++)
{
Console.WriteLine(mc[i].Value);
}
}
else
{
Console.WriteLine("什么都没有");
}
Console.ReadKey();
}
}

results:
存在数据
"A":{1,2,3}
"B":{4,5,6}
"C":{7,8,9}


wuhq030710914 2008-04-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 beelzebub918 的回复:]
那么多的,号,你怎么个splite法呀?最好用正则来做
[/Quote]
LZ请看清楚,上面的不是正则???
Jackie 2008-04-17
  • 打赏
  • 举报
回复
那么多的,号,你怎么个splite法呀?最好用正则来做
wuhq030710914 2008-04-16
  • 打赏
  • 举报
回复
:\s*\(
split结果,在用
(?<=}),
split

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧