//设定搜索范围: Start、Stop
var
  reg: TPerlRegEx;
begin
  reg := TPerlRegEx.Create(nil);

  reg.Subject := 'ababab';
  reg.RegEx   := 'ab';
  reg.Replacement := '◆';

  reg.Start := 1;
  reg.Stop := 2;
  while reg.MatchAgain do
  begin
    reg.Replace;
  end;
  ShowMessage(reg.Subject); //返回: ◆abab


  reg.Subject := 'ababab';
  reg.Start := 3;
  reg.Stop := 4;
  while reg.MatchAgain do
  begin
    reg.Replace;
  end;
  ShowMessage(reg.Subject); //返回: ab◆ab


  reg.Subject := 'ababab';
  reg.Start := 5;
  reg.Stop := 6;
  while reg.MatchAgain do
  begin
    reg.Replace;
  end;
  ShowMessage(reg.Subject); //返回: abab◆

  FreeAndNil(reg);
end;

posted on 2007-12-24 03:29  万一  阅读(5353)  评论(0编辑  收藏  举报