求一正则表达式
<p>你好</p>
结果是:你好
< >中为任意数字或字母或符号,谁知道?

解决方案 »

  1.   

    需求不明确,你这算是提取还是替换呢,给个复杂些的例子,并给出结果string result = Regex.Replace(yourStr, @"<[^>]*>", "");
    MessageBox.Show(result);
      

  2.   

    不好意思,没说清楚,是提取,
    例如:
    <p><font>你好</font></p>
    出来结果是:你好
      

  3.   

    试下是否符合要求MatchCollection mc = Regex.Matches(str, @"<([^\s>]*)[^>]*>([^<>]*)</\1>");
    foreach (Match m in mc)
    {
        richTextBox1.Text += m.Groups[2].Value + "\n";
    }
      

  4.   

    取不到,取到空值
    <p><font size="3" color="#008000">你好</font></p>
    得不到:你好
      

  5.   

    贴你的测试代码,我测试没问题string test = "<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";
    }
      

  6.   

    string str="<p> <font size=\"3\" color=\"#008000\">你好</font> </p> ";                                 
    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;
                                        }
      

  7.   

    打错
    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; 

    刚才的也是别人的,都不行!
      

  8.   


    从哪里搞来的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;
    }
      

  9.   

    不需要用的时候,不要滥用RegexOptions.IgnoreCase|RegexOptions.Compiled这些参数
      

  10.   


    代码都已经给到这份上了,楼主再说不行那我也无话可说最后再强调一下,楼主用的是 mc1[i].Groups["content"].Value
    而我的代码取的是      mc1[i].Groups[2].Value;再不行我也只能对楼主读代码能力和语言表达能力深表遗憾了