implementation{$R *.dfm} uses PerlRegEx; //uses 正则表达式单元procedure TForm1.FormCreate(Sender: TObject);var reg: TPerlRegEx; num: Integer; //用 num 来计数begin reg := TPerlRegEx.Create(); reg.Subject := 'CodeGear Delphi G2007 for Win32'; reg.RegEx := '[FG]\d{4}'; num := 0; while reg.MatchAgain do //MatchAgain 是下一个 begin ShowMessage(reg.MatchedText); //将分别显示: 2 0 0 7 3 2 Inc(num); end; ShowMessage(IntToStr(num)); //6 FreeAndNil(reg);end;
本文转自鹅倌51CTO博客,原文链接:http://blog.51cto.com/kaixinbuliao/1980247 ,如需转载请自行联系原作者