各位大侠好,DELPHI中正则一直用的不太熟悉,希望大家帮下忙
1:自定义正则提取方式INI文件
[Rule]
Url=http://www.haozs.net/proxyip/
Rule=<td>$ip$</td><td>anonymous</td><td>$area$</td>2:我希望能通过正则提取URL中的内容,需要提取的东西为$ip$和$area$
Rule里的东西是对照URL内容里得到的.如何按照上面的定义提取呢?提取结果我想保存到一个数组里.另外我是引用VBSCRIPT里的VBScript_RegExp_55_TLB

解决方案 »

  1.   

    http://topic.csdn.net/u/20070720/15/432A4AD6-B458-4752-B3C1-F5798D3AEFFA.html
      

  2.   

    网页抓取,我是通过自行实现的一个gettag(sAll,sHead,sTail)函数实现的
    sip:=gettag(s,'<td>','</td> <td>anonymous');
    sarea:=gettag(s,'anonymous </td> <td>','</td>');
      

  3.   

    感谢一楼的答案,
    string   strSrc   =   "页中的 <a   href=\ "http://www.baidu.com\ "   class   =   ...> 百   度 </a> "; 
    string   strRegex   =   "(? <url> (? <= <a   href   ?=   ?\ "?)[^\ "> ]+?(?=\ "|> )).*(? <Text> (? <=> )[^ <]+?(?= </a> )) "; 
    Match   res   =   Regex.Match(strSrc,   strRegex); 
    if   (res.Success) 

                MessageBox.Show(res.Groups[ "url "].Value); 
                MessageBox.Show(res.Groups[ "Text "].Value); 
    }这个在DELPHI中不知道如何转换
    二楼,你这样只能提取一个,我是要提取多个的,,
    感谢你们.继续期待
      

  4.   

    恩,就是需要灵活,用户要能自定义取值网址和取值方式
    类似
    [Rule] 
    Url=http://www.haozs.net/proxyip/ 
    Rule= <td>$ip$ </td> <td>anonymous </td> <td>$area$ </td> 
      

  5.   

    好像正则也是需要循环的。这样gettag也可以:
    [Rule] 
    Url=http://www.haozs.net/proxyip/ 
    tagcount=2
    tag1h=<td>
    tag1t=</td> <td>anonymous </td> <td>$area$ </td> 
    tag2h=anonymous </td> <td>
    tag1t= </td> 
      

  6.   

    [Rule] 
    Url=http://www.haozs.net/proxyip/ 
    tagcount=2 
    tag1h= <td> 
    tag1t= </td> <td>anonymous </td> <td>$area$ </td> 
    tag2h=anonymous </td> <td> 
    tag2t= </td> 
      

  7.   

    谢谢你们.
    还不是想要的答案...
    string  strSrc  =  "页中的 <a  href=\ "http://www.baidu.com\ "  class  =  ...> 百  度 </a> "; 
    string  strRegex  =  "(? <url> (? <= <a  href  ?=  ?\ "?)[^\ "> ]+?(?=\ "|> )).*(? <Text> (? <=> )[^ <]+?(?= </a> )) "; 
    Match  res  =  Regex.Match(strSrc,  strRegex); 
    if  (res.Success) 

                MessageBox.Show(res.Groups[ "url "].Value); 
                MessageBox.Show(res.Groups[ "Text "].Value); 
    } 这个如何用在DELPHI中,用过TPerlRegEx的通知帮忙下