求一正则表达式
<p>你好</p>
结果是:你好
< >中为任意数字或字母或符号,谁知道?
<p>你好</p>
结果是:你好
< >中为任意数字或字母或符号,谁知道?
解决方案 »
- 还是字符格式化的问题,第二次提问》》》》
- C#简单例子求高手解答,小弟我就是想不通
- 用C#写的一个UDP的Socket程序,传送多个图片数据,正常显示了几个图片后就报错:一个在数据报套接字上发送的消息大于内部消息缓冲器或其他一些网络限制,或该用户用于接收数据报的缓冲器比数据报小。
- 一道题 一经采纳 50分.................
- 关于DataSet
- 进程关闭的问题
- 100求大虾帮忙!combox绑定报错问题!
- 能不能告诉我AutoResetEvent(在一个多线程程序里面看见的)是什么意思,怎么用啊?
- Visual studio beta2 中WebForm中的 Textbox Web控件的输入值怎么取得?
- docker build .net core 项目报错
- 一直想问的一个问题
- C# 做非规则的窗体
MessageBox.Show(result);
例如:
<p><font>你好</font></p>
出来结果是:你好
foreach (Match m in mc)
{
richTextBox1.Text += m.Groups[2].Value + "\n";
}
<p><font size="3" color="#008000">你好</font></p>
得不到:你好
MatchCollection mc = Regex.Matches(test, @"<([^\s>]*)[^>]*>([^<>]*)</\1>");
foreach (Match m in mc)
{
richTextBox1.Text += m.Groups[2].Value + "\n";
}
Regex htmlRegex1 = new Regex(@"<.*>(.*)?</.*>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
MatchCollection mc1 = htmlRegex1.Matches(str); //抽取标题
string[] div1 = new string[mc1.Count];
for (int i = 0; i < mc1.Count; i++)
{
div1[i] = mc1[i].Groups["content"].Value;
}
string str=" <p> <font size=\"3\" color=\"#008000\">你好 </font> </p> ";
Regex htmlRegex1 = new Regex(@"<([^\s>]*)[^>]*>([^<>]*)</\1>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
MatchCollection mc1 = htmlRegex1.Matches(str); //抽取标题
string[] div1 = new string[mc1.Count];
for (int i = 0; i < mc1.Count; i++)
{
div1[i] = mc1[i].Groups["content"].Value;
}
刚才的也是别人的,都不行!
从哪里搞来的Groups["content"],能行才怪MatchCollection本来就是一个集合,有必要再搞个数组吗,就算是一定要,用泛型也比数组来得容易string test = "<p> <font size=\"3\" color=\"#008000\">你好</font> </p> ";
MatchCollection mc = Regex.Matches(test, @"<([^\s>]*)[^>]*>([^<>]*)</\1>");
List<string> list = new List<string>();
foreach (Match m in mc)
{
list.Add(m.Groups[2].Value);
}算了,我还是按楼主的代码写个吧string test = "<p> <font size=\"3\" color=\"#008000\">你好</font> </p> ";
MatchCollection mc1 = Regex.Matches(test, @"<([^\s>]*)[^>]*>([^<>]*)</\1>");
string[] div1 = new string[mc1.Count];
for (int i = 0; i < mc1.Count; i++)
{
div1[i] = mc1[i].Groups[2].Value;
}
代码都已经给到这份上了,楼主再说不行那我也无话可说最后再强调一下,楼主用的是 mc1[i].Groups["content"].Value
而我的代码取的是 mc1[i].Groups[2].Value;再不行我也只能对楼主读代码能力和语言表达能力深表遗憾了