Bonjour,

Je souhaite utiliser les expressions régulières pour analyser des logs Apache (combined).

J'ai le code suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
unit MPrincipale;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,RegExpr;
 
type
  TFPrincipale = class(TForm)
    ELog: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    EIP: TEdit;
    Label3: TLabel;
    EUtilisateur: TEdit;
    Label4: TLabel;
    EDate: TEdit;
    Label5: TLabel;
    ERequete: TEdit;
    ECode: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    ETaille: TEdit;
    Label8: TLabel;
    EReferer: TEdit;
    Label9: TLabel;
    EUserAgent: TEdit;
    Label10: TLabel;
    ESyntaxe: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;
 
var
  FPrincipale: TFPrincipale;
 
implementation
 
{$R *.dfm}
 
procedure TFPrincipale.Button1Click(Sender: TObject);
var
     RegExpr   : TRegExpr;
begin
     RegExpr := TRegExpr.Create;
     try
          RegExpr.Expression := ESyntaxe.Text;
          if RegExpr.Exec(ELog.Text) then
          begin
               EIP.Text := RegExpr.Substitute('$1');
          end
          else
          begin
               MessageDlg('La ligne n''a pas le bon format !', mtError, [mbOK], 0);
          end;
     finally
          RegExpr.Free;
     end;
end;
 
end.
Voici mes deux variables :
Log : 10.1.1.1 - mondomaine.fr [04/Feb/2008:13:26:49 +0100] "GET /index.php HTTP/1.1" 200 1022 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"

Expression : ^(\d.\d.\d.\d)*
J'ai quelques difficultés avec les expressions régulières malgré l'usage du document d'aide joint avec TRegExpr.

Je n'ai pas d'erreur à l'exécution mais je ne récupère rien dans $1.

Merci,
ZiP