如何同正则提取 { } 中的所有内容 想在html源代码中 用正则方法匹配出{ } 中的文本内容 用c#C#正则源代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Regex reg=new Regex(@"(?<={)[^{}]+(?=})");foreach(Match m in reg.Matches(yourhtml)){ Console.WriteLine(m.Value);} string html="sdsa{123}sa{df}sa";foreach(Match m in Regex.Matches(html,@"(?<=\{)[^{}]*?(?=\})")){ Console.WriteLine(m.Value);}如果{}中还包括{}可以用平衡组参考http://blog.csdn.net/lxcnn/article/details/4402808 string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt string pattern = @"\{((?<Open>\{)|(?<-Open>\})|[\s\S]*)(?(Open)(?!))\}"; foreach (Match m in Regex.Matches(tempStr, pattern)) { string value = m.Value;// } 平衡组 string html =@"sdsa{123}sa{df}sa";//读取txt string pattern = @"\{((?<Open>\{)|(?<-Open>\})|[^{}])*(?(Open)(?!))\}"; foreach (Match m in Regex.Matches(html, pattern)) { Console.WriteLine(m.Value); } 这就和正则没有关系了,你看看你的 DocumentText里边值是不是乱码了 恩 是我编码错了 用了encoding 就好了 谢谢 都进来看看吧! 往access数据库中插入数据报错!!!求救! intptr如何指向字符串 C#的变量到底是个什么机制 PictureBox的问题高手请入 一个关于字符串的简单问题,如果在字符串在包含“”。 什么样的软件最有发展? 前辈留步 请为后生们讲讲.net程序员 必须精通的技术 汉字转换拼音问题 简单的问题求解? TXT文件导入到MySQL数据库 c#查询问题,这怎么不显示了啊?
foreach(Match m in reg.Matches(yourhtml))
{
Console.WriteLine(m.Value);
}
foreach(Match m in Regex.Matches(html,@"(?<=\{)[^{}]*?(?=\})"))
{
Console.WriteLine(m.Value);
}
如果{}中还包括{}可以用平衡组
参考http://blog.csdn.net/lxcnn/article/details/4402808
string pattern = @"\{((?<Open>\{)|(?<-Open>\})|[\s\S]*)(?(Open)(?!))\}";
foreach (Match m in Regex.Matches(tempStr, pattern))
{
string value = m.Value;//
}
string pattern = @"\{((?<Open>\{)|(?<-Open>\})|[^{}])*(?(Open)(?!))\}";
foreach (Match m in Regex.Matches(html, pattern))
{
Console.WriteLine(m.Value);
}