我用TPerlRegEx提取网页的部分内容var
reg:TPerlRegEx;
i:integer;
ss:string;
begin
 reg:=TPerlRegEx.Create(nil);
 reg.RegEx:='<td class="number">(\w*?)</td>.|[\s]*<td class="time">(.*?)</td>.|[\s]*class="ft-gray">(.*?)</span>.|[\s]*<td class="amount outlay">(.*?)</td>';//这里应该可以匹配到SubExpressions1、2、3、4各20条数据
 reg.Subject:=s;
while reg.MatchAgain do
begin
reg.SubExpressions[1]+reg.SubExpressions[2]+reg.SubExpressions[3]+reg.SubExpressions[4];//这里的循环次数怎么就成了80次了……怎么让他循环20次呢,找了很久没找到TPerlRegEx能返回这个数字
end;

解决方案 »

  1.   

    TPerlRegEx没用过
    用标准的VBScript_RegExp_55_TLB参考下吧const
      CR   = #13;
      LF   = #10;
      CRLF = CR + LF;function TestReg(RegPattern, S: string):string;
    var
      Regexp: TRegExp;
      oMatchs:MatchCollection;
      oMatch:Match;
      oSub:SubMatches;
      i,x:integer;
    begin
      Result:='';
      Regexp := TRegExp.Create(nil);
       //Regexp.Multiline:=False;
      Regexp.Global:=True;
      Regexp.IgnoreCase:=True;  Regexp.Pattern:=RegPattern;  oMatchs:=Regexp.Execute(S) as MatchCollection;
      for i:=0 to oMatchs.Count - 1 do begin
        oMatch := oMatchs.Item[i] as Match;
        Result:= Result + '>'+ oMatch.Value + CRLF;
        oSub:=oMatch.SubMatches as SubMatches;
        for x:=0 to oSub.Count -1 do
          Result:= Result + '-->' + oSub.Item[x] + CRLF;
      end;
      Regexp.Free;
    end;