求一htm代码段的批配正则 <DIV id=content>任意字符有可能是多行,也可能是一行</DIV><DIV id="content">任意字符有可能是多行,也可能是一行</DIV><div id=content>任意字符有可能是多行,也可能是一行</div><div id="content">任意字符有可能是多行,也可能是一行</div>如何用一个正则同时能在以上四种情况都取到"任意字符有可能是多行,也可能是一行"部分内容? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <div[^>]*id\s*=['"]?content[^>]*>([\s\S]*?)</div> try...string test = @"<DIV id=content>任意字符有可能是多行,也可能是一行</DIV><DIV id=""content"">任意字符有可能是多行,也可能是一行</DIV><div id=content>任意字符有可能是多行,也可能是一行</div><div id=""content"">任意字符有可能是多行,也可能是一行</div>";Regex reg = new Regex(@"(?is)<div\s+id=(['""]?)content\1\s*>(.*?)</div>");MatchCollection mc = reg.Matches(test);foreach (Match m in mc){ richTextBox2.Text += m.Groups[2].Value + "\n";} string str = "<DIV id=content>任意字符有可能是多行,也可能是一行</DIV>" + "<DIV id=\"content\">任意字符有可能是多行,也可能是一行</DIV>" + "<div id=content>任意字符有可能是多行,也可能是一行</div>" + "<div id=\"content\">任意字符有可能是多行,也可能是一行</div>"; Regex reg = new Regex(@"(?is)<div[^>]*?id=(['""\s]?)content\1[^>]*?>(?<content>((?!</?div).)*)"); MatchCollection match = reg.Matches(str); foreach (Match m in match) { Response.Write(m.Groups["content"].Value + "<br/>"); }/*任意字符有可能是多行,也可能是一行任意字符有可能是多行,也可能是一行任意字符有可能是多行,也可能是一行任意字符有可能是多行,也可能是一行*/ 新人求教 freetextbox文件复制问题~~~~~~~~~~~~~~~~~~~~~~~~~~~ treeview控件 NavigateUrl 问题 求救 关于asp.net2.0中的webpart问题 更新网站问题? DataRow[]问题 一下午了急啊! treeveiw问题,由于数据量较大,如何在点击节点才加载(才从数据库中取)节点下的子节点信息? access数据库中的数值的值段在的OleDbType是什么? 请问可以让panel透明吗? 在asp.net中使用WebBrowser的问题 前,后台传值问题(求有丰富经验的高人) asp.net mvc空间商的问题
<div[^>]*id\s*=['"]?content[^>]*>([\s\S]*?)</div>
也可能是一行</DIV>
<DIV id=""content"">任意字符有可能是多行,也可能是一行</DIV>
<div id=content>任意字符有可能是多行,
也可能是一行</div>
<div id=""content"">任意字符有可能是多行,也可能是一行</div>
";
Regex reg = new Regex(@"(?is)<div\s+id=(['""]?)content\1\s*>(.*?)</div>");
MatchCollection mc = reg.Matches(test);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[2].Value + "\n";
}
+ "<DIV id=\"content\">任意字符有可能是多行,也可能是一行</DIV>"
+ "<div id=content>任意字符有可能是多行,也可能是一行</div>"
+ "<div id=\"content\">任意字符有可能是多行,也可能是一行</div>";
Regex reg = new Regex(@"(?is)<div[^>]*?id=(['""\s]?)content\1[^>]*?>(?<content>((?!</?div).)*)");
MatchCollection match = reg.Matches(str);
foreach (Match m in match)
{
Response.Write(m.Groups["content"].Value + "<br/>");
}
/*
任意字符有可能是多行,也可能是一行
任意字符有可能是多行,也可能是一行
任意字符有可能是多行,也可能是一行
任意字符有可能是多行,也可能是一行
*/