求一个正则表达式。要求是在 <SPAN class=question-title>我的电脑</SPAN>中提取出“我的电脑”这几个字

解决方案 »

  1.   

    string str = "<SPAN class=question-title>我的电脑</SPAN>";
    str = Regex.Replace(str,"<[^<>]+>","");
    Console.WriteLine(str);
      

  2.   

    不好意思,我的问题可能没描述太清楚。
    而我的需求是要在整个网页的HTML代码中只提取出question-title这个类标签中的文字,即这里的“我的电脑”。楼上的答案实际只是去掉了所有<>标签
      

  3.   

                string str = "<SPAN class=question-title>我的电脑</SPAN>";
                Match m = Regex.Match(str, @"(?<=class=question-title[^>]*>)[^<]+");
                Console.WriteLine(m);
      

  4.   

    正则替换replace\<[^<>]+\>为空即可
      

  5.   


    void Main()
    {
     string s="<SPAN class=question-title>我的电脑</SPAN>";
     foreach(Match m in Regex.Matches(s,@"(?is)<span[^>]*?class=(['""]?)question-title\1[^>]*>([^<]+)</span>"))
     {
     Console.WriteLine(m.Groups[2].Value);
     }
    //我的电脑}
      

  6.   

    Regex reg = new Regex(@"(?is)<span\s=calss=""question-title""[^>]*>(.*?)</span>");
    MatchCollection mc = reg.Matches(str);
    foreach (Match m in mc)
    {
        TextBox2.Text += m.Groups[1].Value + "\n";
    }