高份求一个正则表达式 谢谢大家了

showmy 2008-10-08 12:18:25
{"uid":36,"name":"gaoluxia@163.com","email":"gaoluxia@snda.com","item":null,"mobile":"","imp":"0"},{"uid":3,"name":"glx0444012045","email":"glx0444012045@163.com","item":null,"mobile":"","imp":"0"},{"uid":28,"name":"桂李","email":"lghran@yahoo.com.cn","item":null,"mobile":"","imp":"0"},{"uid":6,"name":"happysundy419","email":"happysundy419@sina.com","item":null,"mobile":"","imp":"0"},{"uid":54,"name":"何波","email":"robust_1983@126.com","item":null,"mobile":"","imp":"0"},{"uid":4,"name":"hgaoirene","email":"hgaoirene@yahoo.com.cn","item":null,"mobile":"","imp":"0"},{"uid":25,"name":"honghairen14@sina.com","email":"honghairen14@sina.com","item":null,"mobile":"","imp":"0"},

 string rx = "";
Regex re = new Regex(rx,RegexOptions.IgnoreCase);
MatchCollection mc = re.Matches(b);
if (mc != null && mc.Count > 0)
{
for (int i = 0; i < mc.Count; i++)
{
Match m = mc[i];
if (m.Groups.Count > 2)
{
MailContact mailContact = new MailContact();
mailContact.Name = m.Groups[1].Value;
mailContact.Email = m.Groups[2].Value;
list.Add(mailContact);
}
}
}


取出name和email
...全文
135 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
kfps8kfps8 2008-10-08
  • 打赏
  • 举报
回复
关注,请正则高手来解决!
showmy 2008-10-08
  • 打赏
  • 举报
回复
吃饭 回来就给分
hackztx 2008-10-08
  • 打赏
  • 举报
回复

string str = "{\"uid\":36,\"name\":\"gaoluxia@163.com\",\"email\":\"gaoluxia@snda.com\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},{\"uid\":3,\"name\":\"glx0444012045\",\"email\":\"glx0444012045@163.com\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},{\"uid\":28,\"name\":\"桂李\",\"email\":\"lghran@yahoo.com.cn\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},{\"uid\":6,\"name\":\"happysundy419\",\"email\":\"happysundy419@sina.com\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},{\"uid\":54,\"name\":\"何波\",\"email\":\"robust_1983@126.com\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},{\"uid\":4,\"name\":\"hgaoirene\",\"email\":\"hgaoirene@yahoo.com.cn\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},{\"uid\":25,\"name\":\"honghairen14@sina.com\",\"email\":\"honghairen14@sina.com\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},";
MatchCollection mc = Regex.Matches(str, "name\":\"(.+?)\".+?:\"(.+?)\"", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
Console.WriteLine(m.Groups[1].Value);
Console.WriteLine(m.Groups[2].Value);
Console.WriteLine("***********************************************");
}
Console.ReadKey();
showmy 2008-10-08
  • 打赏
  • 举报
回复
自己搞定` 正则还是很不错的
fellowcheng 2008-10-08
  • 打赏
  • 举报
回复
try

"\"name\":([^,])+,"

"\"email\":([^,])+,"

然后拆分字符
gen06 2008-10-08
  • 打赏
  • 举报
回复
"name":"([^"]+?)","email":"([^"]+?)"
grady.lu 2008-10-08
  • 打赏
  • 举报
回复
string s ="{\"uid\":36,\"name\":\"gaoluxia@163.com\",\"email\":\"gaoluxia@snda.com\",\"item\":null,\"mobile\":\"\",\"imp\":\"0\"},";
Regex regex = new Regex("\"name\":\"(?<name>[^\"]*)\",\"email\":\"(?<email>[^\"]*)\"");

foreach (Match m in regex.Matches(s))
{
Console.Write(m.Groups["name"].Value);
Console.Write(m.Groups["email"].Value);
}
Console.Read();
grady.lu 2008-10-08
  • 打赏
  • 举报
回复
\"name\":\"(?<name>[^\"]*)\",\"email\":\"(?<email>[^\"]*)\"
fellowcheng 2008-10-08
  • 打赏
  • 举报
回复
其实可以直接用字符串拆分来解决呀
POPO_POPO 2008-10-08
  • 打赏
  • 举报
回复
你的字符串这么有规则 用 string.Split就能很容易的解决。
消失的尘芥 2008-10-08
  • 打赏
  • 举报
回复
http://regxlib.com
消失的尘芥 2008-10-08
  • 打赏
  • 举报
回复
给一个正则表达式网址你,里面有你想要的东西
yaokai0405 2008-10-08
  • 打赏
  • 举报
回复
期待...
sunchf 2008-10-08
  • 打赏
  • 举报
回复
期待...
fangsp 2008-10-08
  • 打赏
  • 举报
回复
帮顶一个
期待高手的到来

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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