1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| unit Princ;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ,
{$IF CompilerVersion >= 22.0} // Delphi XE ou supérieur
RegularExpressionsCore;
{$ELSE}
PerlRegex; (* http://www.regular-expressions.info/download/TPerlRegEx.zip *)
{$IFEND}
type
TF_Princ = class(TForm)
Label1: TLabel;
E_Fichier: TEdit;
E_Filtre: TEdit;
Label2: TLabel;
Label3: TLabel;
E_Regex: TEdit;
Btn_Verif: TButton;
procedure Btn_VerifClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
F_Princ: TF_Princ;
REGEX : String ;
implementation
{$R *.dfm}
{ ================================================================ }
function TraiteFiltre(Const S : String) : String ;
Var
expression : String ;
Begin
expression:=StringReplace(S,'.','\.',[rfReplaceAll]); // échapper le .
expression:=StringReplace(expression,'*','\w*',[rfReplaceAll]); // remplacer *
expression:=StringReplace(expression,'?','\w{1}',[rfReplaceAll]); // remplacer le(s) point(s) interrogation
expression:='^'+expression+'\z';
Result := expression ;
End ;
{ ================================================================ }
function IsValidString(const s: string): boolean;
var
expr: TPerlRegex;
begin
expr := TPerlRegex.Create;
expr.Subject := utf8string(s);
expr.RegEx := REGEX;
result := expr.Match;
expr.Free;
end;
{ ================================================================ }
procedure TF_Princ.Btn_VerifClick(Sender: TObject);
Var
Filtre : String ;
Fichier : String ;
begin
E_Regex.Text := EmptyStr ;
Filtre := E_Filtre.Text ;
Fichier := E_Fichier.Text ;
REGEX := TraiteFiltre(Filtre) ;
E_Regex.Text := REGEX ;
If IsValidString(Fichier) Then
ShowMessage('Concordance trouvée')
Else
ShowMessage('Concordance non trouvée') ;
end;
{ ================================================================ }
end. |
Partager