bonjour,
j'ai testé je ne sais pas trop combien de code regex mais toujours la même galère, j'arrive toujours pas a finioler mon code, en fait j'ai une premiere fonction qui permet de divisé une ip (je la mais pour pouvoir comprendre le reste ) :
puis par la suite je met un code regex, bon ici c'en est un totalement a l'arrache j'ai abandonné apres une trentraine d'essais :s
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 function Explode(Text, Separator: String): TArrayOfDString; var Index, LenSeparator, aPos: LongInt; lignes: TArrayOfDString; begin try LenSeparator := Length(Separator); aPos := Pos(Separator, Text); //Application.MessageBox(PChar(balises[i][0] + ' ' + balises[i][1]),'Essai'); if(aPos <> 0) then while (aPos <> 0) do begin if(Text[aPos+1] = '.') then Text[aPos+1] := '0'; setlength(lignes, length(lignes)+1); lignes[length(lignes)-1] := Strtoint(Copy(Text, 1, aPos - 1)); Delete(Text, 1, aPos + Length(Separator)-1); aPos := Pos(Separator, Text); end else begin setlength(lignes, length(lignes)+1); lignes[length(lignes)-1] := Strtoint(Copy(Text, 1, length(Text))); end; finally Result := lignes; end; end;
en bref, l'ip est fausse ça me fait :
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 procedure TForm2.Edit1Change(Sender: TObject); var LesChaines: TArrayOfDString; begin Memo1.Clear; // verifip((Sender as TEdit).Text, memo1.Lines,false,['.']); if(MatchesMask((Sender as TEdit).Text,'[0-9]*[0-9]*[0-9]*.[0-9]*[0-9]*[0-9]*.[0-9]*[0-9]*[0-9]*.[0-9]*[0-9]*[0-9]*')) then LesChaines := Explode((Sender as TEdit).Text , '.' ); if(LesChaines <> nil) then try if (LesChaines[0] = 0 ) or (LesChaines[1] = 0 ) or (LesChaines[2] = 0 ) or (LesChaines[3] = 0 ) then begin (Sender as TEdit).Color := clRed; BitBtn1.Enabled := false; end else begin if (LesChaines[0] < 256) and (LesChaines[0] > 0) and (LesChaines[1] < 256) and (LesChaines[1] >= 0) and (LesChaines[2] < 256) and (LesChaines[2] >= 0) and (LesChaines[3] < 256) and (LesChaines[3] > 0) then begin (Sender as TEdit).Color := clWhite; BitBtn1.Enabled := true; end else begin (Sender as TEdit).Color := clRed; BitBtn1.Enabled := false; end end except on EConvertError do (Sender as TEdit).Color := clRed; on EAccessViolation do (Sender as TEdit).Color := clRed; end else begin (Sender as TEdit).Color := clRed; BitBtn1.Enabled := false; end; end;
elle est bonne j'obtient :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 (Sender as TEdit).Color := clRed; BitBtn1.Enabled := false;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 (Sender as TEdit).Color := clWhite; BitBtn1.Enabled := true;
Partager