<h1>产品规格</h1>STGX2202-1570B<h1>生产厂商</h1>华为科技<h1>产品质保</h1>3年限<h1>...</h1>
...我的问题是:
1.我要取</h1>...<h1>的内容,也就是“STGX2202-1570B”、“华为科技”、“3年限”这些。
  <h1>标签中可能会带有一些属性,比如<h1 color='red'>。
2.最后一个</h1>到结尾不存在<h1>了,但也要将内容取出来,也就是从最后一个</h1>标签到结尾的内容匹配出来。
麻烦大家给个正则,谢谢大家的帮助。

解决方案 »

  1.   

    string s = @"<h1>产品规格</h1>
    STGX2202-1570B
    <h1>生产厂商</h1>
    华为科技
    <h1>产品质保</h1>
    3年限
    <h1>...</h1>
    其他到最后";
    MatchCollection matches = Regex.Matches(s, @"(?is)(?<=</h1>)[^(<h1>)]+");
    foreach (Match match in matches)
    Response.Write(match.Value + "<br/>");
      

  2.   

    using System;
    using System.Net;
    using System.Collections.Generic;
    using System.Xml;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication13
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "<h1>产品规格</h1>"
                        + "STGX2202-1570B"
                        + "<h1>生产厂商</h1>"
                        + "华为科技"
                        + "<h1>产品质保</h1>"
                        + "3年限"
                        + "<h1>test</h1>"
                        + "<p>剩下文本内容及标签等</p>";
                Regex rgx1 = new Regex(@"(?is)</h1>([^<]*)<h1>");
                foreach (Match m in rgx1.Matches(str))
                {
                    Console.WriteLine(m.Groups[1].Value);
                }
                Console.WriteLine("---------------");
                Regex rgx2 = new Regex(@"(?is).*</h1>(.*)");
                Console.WriteLine(rgx2.Match(str).Groups[1].Value);        }
        }}/*
    STGX2202-1570B
    华为科技
    3年限
    ---------------
    <p>剩下文本内容及标签等</p>
     */
      

  3.   

                string str = @"<h1>产品规格</h1>
    STGX2202-1570B
    <h1>生产厂商</h1>
    华为科技
    <h1>产品质保</h1>
    3年限
    <h1>...</h1>
    其他到最后";
                Regex reg = new Regex(@"(?is)(?<=</h1>)(?:(?!</?h1).)*");
                foreach (Match m in reg.Matches(str))
                    Console.WriteLine(m.Value);
      

  4.   


    STGX2202-1570B、华为科技、3年限 这些内容中带有html标签的。
      

  5.   

    <h1>..</h1><span>aaa</span>
    类似这样?
    就是要取的数据里面有包含标签,你不想要那些标签?
      

  6.   

    <h1>产品规格</h1><style color='red'>STGX2202-1570B</style><h1>生产厂商</h1>华为科技<h1>产品质保</h1>3年限<h1>...</h1>abc
      

  7.   

    <h1>产品规格</h1><style color='red'>STGX2202-1570B</style><h1>生产厂商</h1>华为科技<h1>产品质保</h1>3年限<h1>...</h1>abc
    这样取出:
    <style color='red'>STGX2202-1570B</style>
    华为科技
    3年限
    abc谢谢。
      

  8.   

                string str = @"<h1>产品规格</h1><style color='red'>STGX2202-1570B</style><h1>生产厂商</h1>华为科技<h1>产品质保</h1>3年限<h1>...</h1>abc";
                Regex reg = new Regex(@"(?is)(?<=</h1>)(?:(?!<h1).)*");
                foreach (Match m in reg.Matches(str))
                    Console.WriteLine(m.Value);
      

  9.   

    你给的那个正则在没有HTML标签的情况下可以,假如有了标签就匹配不到了。<h1>产品规格</h1><style color='red'>STGX2202-1570B</style><h1>生产厂商</h1>华为科技<h1>产品质保</h1>3年限<h1>...</h1>abc
    这样取出:
    <style color='red'>STGX2202-1570B</style> (取<h1>...<h1>之间全部内容,带HTML标签)
    华为科技
    3年限
    abc
      

  10.   

    被lz搞晕了。
    取出的结果是
    <style color='red'>STGX2202-1570B</style> (取<h1>...<h1>之间全部内容,带HTML标签)
    华为科技
    3年限
    abc然后lz是不想要<style>等标签?
      

  11.   


               string str = @"<h1>产品规格</h1><style color='red'>STGX2202-1570B</style><h1>生产厂商</h1>华为科技<h1>产品质保</h1>3年限<h1>...</h1>abc";
                Regex reg = new Regex(@"(?is)(?<=</h1>)\s*(?:<[^>]*?>)?([^><]+)");
                foreach (Match m in reg.Matches(str))
                    Console.WriteLine(m.Groups[1].Value);
    /*
    STGX2202-1570B
    华为科技
    3年限
    abc
    */
      

  12.   

    string Content = @"<h1>产品规格</h1><style color='red'>STGX2202-1570B</style><h1>生产厂商</h1>华为科技<h1>产品质保</h1>3年限<h1>...</h1>abc";用你的正则Regex reg = new Regex(@"(?is)(?<=</h1>)(?:(?!<h1).)*"),取不出><style color='red'>STGX2202-1570B</style>了。只能取到:
    华为科技
    3年限
    abc
      

  13.   

    我是想把</h1>...<h1>之间的所有内容(包含标签)都取到。谢谢
      

  14.   

    图片?就是传到csdn上去引用路径就可以。