//設定搜索范圍: 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;