Skip to content
Benjamin Rosseaux edited this page Sep 7, 2015 · 3 revisions

#ExtractAll

var MultiExtractions:TFLREMultiStrings;

FLREInstance:=TFLRE.Create('(\w+)\s(\w+)',[]);
try
 if FLREInstance.ExtractAll('Word pair - Pair Words',MultiExtractions) then begin
  for i:=0 to length(MultiExtractions)-1 do begin
   for j:=0 to length(MultiExtractions[i])-1 do begin
    write('"',MultiExtractions[i,j],'" ');
   end;
   writeln;
  end;
 end;
 SetLength(MultiExtractions,0);
finally
 FLREInstance.Free;
end;

#Split

var SplittedStrings:TFLREStrings;

FLREInstance:=TFLRE.Create('\s+',[]);
try
 if FLREInstance.Split('Hello world    this is a test',SplittedStrings) then begin
  for i:=0 to length(SplittedStrings)-1 do begin
   writeln(SplittedStrings[i]);
  end;
 end;
finally
 SetLength(SplittedStrings,0);
 FLREInstance.Free;
end;

#ReplaceCall

type TExample=class
      public
       function Callback(const Input:PFLRERawByteChar;const Captures:TFLRECaptures):TFLRERawByteString;
     end;

function TExample.Callback(const Input:PFLRERawByteChar;const Captures:TFLRECaptures):TFLRERawByteString;
begin
 // FLREPtrCopy is needed here instead copy, because the PFLRERawByteChar-indexing and the values inside the Captures array here are 0-based, not 1-based
 result:=FLREPtrCopy(Input,Captures[3].Start,Captures[3].Length)+'.'+
         FLREPtrCopy(Input,Captures[2].Start,Captures[2].Length)+'.'+
         FLREPtrCopy(Input,Captures[1].Start,Captures[1].Length);
end;

var FLREInstance:TFLRE;
    Example:TExample;
begin
 FLREInstance:=TFLRE.Create('(\d+)\/(\d+)\/(\d+)',[]);
 try
  Example:=TExample.Create;
  try
   writeln(FLREInstance.ReplaceCallback('123/456/789',Example.Callback)); // prints 789.456.123
  finally
   Example.Free;
  end;
 finally
  FLREInstance.Free;
 end;
 readln;
end;
Clone this wiki locally