html:  <div id="main"><div>testxxxxxxxxxxxxxxx</div><div class="abc cf01">test1</div><div class="def cf01">test2</div><div>testxxxxxxxxxxxxxxxzzzzzzzzzzzzz</div></div>
需要取得数据有两块
1、当class类中含有cf01类名的,需要将它class类名abc  def  取出 
2、根据取出的class类名abc  def取得div标签值 test1  test2

解决方案 »

  1.   

     string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt                var result = Regex.Matches(tempStr, @"(?i)<div[^>]*?class=(['""]?)(\S+?)\s*?cf01[^'""]*?\1[^>]*?>([^<>]*?)\s*?</div>").Cast<Match>().Select(a => new { 
                    className=a.Groups[2].Value,
                    text=a.Groups[3].Value
                    });
                    /*
                     + [0] { className = "abc", text = "test1" } <Anonymous Type>
                    + [1] { className = "def", text = "test2" } <Anonymous Type>                 */
      

  2.   

    先写第一个正则  (?is)(?<=class=")(?<name>.*?)cf01
    然后通过name从group中取就可以了 
    MATCH[0]: 'abc cf01'   [index=57]
       GROUP[name]: 'abc '   [index=57]
    MATCH[1]: 'def cf01'   [index=90]
       GROUP[name]: 'def '   [index=90]