【坐等】字符串分割问题 已知html标签,例如“...<div>...<div>...</div>...</div>...”如何正确读取一个标签的内的文本,听说可以用正则不知道咋写的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20090814/11/2b26498c-feb0-4c9e-b03c-4e286c45b4cf.html string s = "<body><div>你好</div><div id=\"div1\">我好</div></body>"; MatchCollection matches=Regex.Matches(s, @"(?is)<div[^>]*>(.*?)</div>"); foreach (Match match in matches) Response.Write(match.Groups[1].Value + "<br/>"); 当<div>标签内部再套一个<div>标签的时候就截取了错误的结尾标签 http://www.cnblogs.com/qiantuwuliang/archive/2011/06/11/2078329.html string str = "div前面<div id=\"d\">外面div<div>里面div</div>外面div</div>div后面"; Regex reg = new Regex(@"(?is)<div[^>]*?id=""d""[^>]*?>(?:(?!</?div).)*(((?<Open><div[^>]*?>)(?:(?!</?div).)*)*((?<-Open></div>)(?:(?!</?div).)*)*)*(?(Open)(?!))</div>"); Console.WriteLine(reg.Match(str).Value); Regex regex = new Regex( ">([^<]*)(>?<a[^<]*</a)*", RegexOptions.IgnoreCase ); 这个不错,可惜js或perl下不能用 C# 中使用OpenDataSource()函数 怎样改变“只读”文本框的背景色???【求助】 如何判断并读取pdf文档中的某些信息??各位大虾,帮帮忙阿。。要命的 richTextBox里面怎么加入图像阿 TextBox的文本不能选择 请教弹出窗口的刷新,自动又弹出新窗口问题. ClientA怎样得到Server发回来的ClientA的映射端口啊? 关于用户界面风格统一有什么办法? 如何用C#实现签入签出功能 如何将webform中的image控件的数据写到数据中,或者写到数组中? 点击按钮 数据保存了两次 C#有关消息群发并得到相应回复的处理方法
MatchCollection matches=Regex.Matches(s, @"(?is)<div[^>]*>(.*?)</div>");
foreach (Match match in matches)
Response.Write(match.Groups[1].Value + "<br/>");
Regex reg = new Regex(@"(?is)<div[^>]*?id=""d""[^>]*?>(?:(?!</?div).)*(((?<Open><div[^>]*?>)(?:(?!</?div).)*)*((?<-Open></div>)(?:(?!</?div).)*)*)*(?(Open)(?!))</div>");
Console.WriteLine(reg.Match(str).Value);