TPerlRegExEscapeRegExChars (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses the TPerlRegEx EscapeRegExChars method.

Code

// To search for '1+1' as literal text, use:
PerlRegEx1.RegEx := PerlRegEx1.EscapeRegExChars('1+1');

// which does the same as:
PerlRegEx1.RegEx := '1\+1';

procedure TForm1.Button1Click(Sender: TObject);
begin
  with PerlRegEx1 do begin
    Subject := 'Looking for 1+1 in my string';
    RegEx := PerlRegEx1.EscapeRegExChars('1+1');
    if Match then
    begin
      RegEx := '1\+1';
      if Match then ShowMessage('1+1 found both ways.');
    end;
  end;
end;

Uses