008.ComputeReplacement
Delphi
function ComputeReplacement: UTF8String;
类型:function
可见性:public
所在单元:System.RegularExpressionsCore
父类:TPerlRegEx
取出替换内容,不修改Subject
测试代码:
program Match; {$APPTYPE CONSOLE} uses System.SysUtils, System.RegularExpressionsCore; var regular: TPerlRegEx; i: Integer; begin try regular := TPerlRegEx.Create; with regular do regular.Subject := 'jerry loves study' ; regular.RegEx := '(tom|jerry) (enjoy|loves|hates) study'; if regular.Match then for i := 1 to regular.GroupCount do begin regular.Replacement := '\' + IntToStr(i); Writeln(regular.ComputeReplacement); end;
FreeAndNil(regular); Readln; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
结果: