http://dev.csdn.net/develop/article/17/article/17/article/17/article/17/article/17/article/17/17735.shtm没学好,希望你能学好啊。
给点间接的建议吧 

解决方案 »

  1.   

    呵呵,谢谢了,我会好好学的,可是现在我琢磨了好长时间,还是想不出来这两个问题:1. 正则表达式可能不可能形成死循环?从原理上讲不应该构成死循环的,如果是这样的话,在某些
       时候正则表达式的效率会很低下,那这种情况什么时候会发生?
    2. 对于嵌套结构,正则表达式如何能够处理.比如:
       <table>1
           <table>11</table>
           <table>12</table>
       </table>
      
       <table>2
       </table>
       如何能够用正则表达式分别把每一对<table>与</table>之中的内容提出来,可以分多步实现.
       
       没有经验,请高手不吝赐教啊,谢谢啦.
      

  2.   

    1. could be infinite loop, but also possibly, it takes extremely long to execute because of the complexity of your regular expressions and all the backtrackings involvednormally, don't try complicated expressions in the beginning, try some simple ones and build on them2. 
    >>如何能够用正则表达式分别把每一对<table>与</table>之中的内容提出来,可以分多步实参考
    http://www.rassoc.com/gregr/weblog/archive.aspx?post=590
      

  3.   

    Great,Thanks Sauser A Lot! I have just read this article and test the regular expression 
    for a long time. This regular expression is powerful and it do solve my problem, but I still can't see how the "(?<DEPTH>)" and "(?<-DEPTH>)" works.For example,using the following regular expression:    "(?:\<table[^>]*?\>)(?<table>(?>(?:\<table\>)(?<DEPTH>)|(?:\</table\>)(?<-DEPTH>)|.)+)(?(DEPTH)(?!))(?:\</table\>)"
        
        If the input is :      <table>0</table> 
        The result match is:   <table>0</table>
        
        If the input is :      <table>0</table></table>
        The result match is:   <table>0</table></table>    If the input is :      <table>0</table></table></table>
        The result match is:   <table>0</table></table></table>    in fact,no matter how many "</table>" between "<table>" and the last "</table>",the expression can always match string between the first "<table>" and the corresponding last "</table>". I have searched the web for a long time,there's little saying about this. Can you help me?  Thanks a lot,:).       
      

  4.   

    对不起,思归大哥,我刚才不小心写错您的名字了,现在纠正一下,Great,Thanks Saucer A Lot! I have just read this article and test the regular expression for a long time. This regular expression is powerful and it do solve my problem, but I still can't see how the "(?<DEPTH>)" and "(?<-DEPTH>)" works.For example,using the following regular expression:    "(?:\<table[^>]*?\>)(?<table>(?>(?:\<table\>)(?<DEPTH>)|(?:\</table\>)(?<-DEPTH>)|.)+)(?(DEPTH)(?!))(?:\</table\>)"
        
        If the input is :      <table>0</table> 
        The result match is:   <table>0</table>
        
        If the input is :      <table>0</table></table>
        The result match is:   <table>0</table></table>    If the input is :      <table>0</table></table></table>
        The result match is:   <table>0</table></table></table>    in fact,no matter how many "</table>" between "<table>" and the last "</table>",the expression can always match string between the first "<table>" and the corresponding last "</table>". I have searched the web for a long time,there's little saying about this. Can you help me?  Thanks a lot,:).
      

  5.   

    @"<table>(?><table>(?<DEPTH>)|</table>(?<-DEPTH>)|.?)+(?(DEPTH)(?!))</table>";doesn't seem to work, but try (although this will cause other problems if you have other tags)@"<table>(?><table>(?<DEPTH>)|</table>(?<-DEPTH>)|[^<]?)+(?(DEPTH)(?!))</table>"regular expressions cannot handle very complicated situations
      

  6.   

    谢谢思归大哥,现在我至少知道完全用正则表达式做网页分析是不够的,但现在我又有点迷惘了,为了提高网页的分析效率和可靠性,我已经尝试过以下几种不同的方法:1.完全依赖正则表达式法(如上),感觉效率和稳定性都不太理想
    2.依靠mshtml组件,感觉稳定性很不错,但效率还是不高,尤其是特消耗CPU,此外访问某些网页还会弹出对话框
    3.完全用string的insert,replace等操作,效率还是不高,而且稳定性也需要测试我的目的很单一,就是分析网页中的表格,忽略其他网页元素,最难解决的就是表格的嵌套,由于经验少,时间短,一时还没想出一个合适的解决方案,请问能否给提示一下,一般这方面的问题是如何解决的,感激不尽!
      

  7.   

    I would suggest you look into SGMLReader and try to convert HTML to XML or see if you can find a library does similar things
    http://www.eggheadcafe.com/articles/20030317.asphttp://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=b90fddce-e60d-43f8-a5c4-c3bd760564bcrelatively, it is easier to work with XML