关于p标签中带换行的正则匹配 <p style="text-align: center"> </p><p> </p>上面这段代码用什么能匹配呢?就是p标签里是空格的就匹配,p标签里有内容的不匹配。另外,下面这段正则应该是启用了不区分大小写的单行模式了吧,那怎么不加\\s还不行呢~(?is)<p[^>]{0,}>\\s* \\s*</p> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str = @"<p style=""text-align: center""> </p><p> </p>"; Regex reg = new Regex(@"(?is)<p[^>]*?>\s* \s*</p>"); foreach (Match m in reg.Matches(str)) Console.WriteLine(m.Value); 木有问题啊。 string str = @"<p style=""text-align: center""> </p><p> </p>"; Regex reg = new Regex(@"(?is)<p[^>]*?>\s* \s*</p>"); foreach (Match m in reg.Matches(str)) { Console.WriteLine(m.Value); Console.WriteLine("==="); } /*<p style=""text-align: center""> </p>===<p> </p>===*/ 如果有N个" "呢? string str = @"<p style=""text-align: center""> </p>"; string str = @"<p style=""text-align: center""> </p><p> </p><p style=""text-align: center""> </p>"; Regex reg = new Regex(@"(?is)<p[^>]*?>(\s* )+\s*</p>"); foreach (Match m in reg.Matches(str)) { Console.WriteLine(m.Value); Console.WriteLine("==="); } 还是不全~不会跟我用.net4.0有关系吧~ 貌似用count能得出3,但用"Response.Write(reg.Matches(Finally)[i].Value + "<BR>");"得出来的就是空的。也奇怪了,用下面这段做替换就不完全匹配for (int i = 0; i < reg.Matches(Finally).Count; i++) { Response.Write("-=-"+reg.Matches(Finally)[i].Value + "<BR>"); }用下面的就可以了~foreach (Match t in reg.Matches(Finally)) { Finally = Finally.Replace(t.Value, ""); } 浏览器阻止activeX怎么办? C#多线程中for循环与while循环的奇怪问题与跨线程安全访问控件的异常? Closing 事件过时问题 dgv控件里的单元数据在不同form中的txtbox中显示 c#将txt文件导入数据库的问题 散分,顺便问个VSS的小问题 打印预览问题 调用控件的方法,什么时候需要要依赖于Invoke/BeginInvoke这样的方式? 一个对arraylist的赋值问题! 数组问题 两个函数,仅仅是类型不同,函数代码相同,该如何写成一个函数。如: 如果让richtextbox滚动到最底部,而不出现空白区域或者隐藏半行文字
</p>
<p>
</p>";
Regex reg = new Regex(@"(?is)<p[^>]*?>\s* \s*</p>");
foreach (Match m in reg.Matches(str))
Console.WriteLine(m.Value);
string str = @"<p style=""text-align: center"">
</p>
<p>
</p>";
Regex reg = new Regex(@"(?is)<p[^>]*?>\s* \s*</p>");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Value);
Console.WriteLine("===");
}
/*
<p style=""text-align: center"">
</p>
===
<p>
</p>
===
*/
</p>";
</p>
<p>
</p><p style=""text-align: center"">
</p>";
Regex reg = new Regex(@"(?is)<p[^>]*?>(\s* )+\s*</p>");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Value);
Console.WriteLine("===");
}
{
Response.Write("-=-"+reg.Matches(Finally)[i].Value + "<BR>");
}用下面的就可以了~foreach (Match t in reg.Matches(Finally))
{
Finally = Finally.Replace(t.Value, "");
}