[Lazarus] [resolved] How to use TRegExpr class (in synregexpr.pas)

FreeMan freeman35 at delphiturkiye.com
Fri Oct 25 13:31:51 CEST 2013


This is version is penultimate version :)
'127.000. 0 .01 ' result is '127.0.0.1'
I tested this in:
Kubuntu 13.10 x64
fpc svn update 25845
lazarus svn update 43320

function IP4OK(pT: String): String;
var r  : TRegExpr;
     i,j: Integer;

     function My_Trim(S : String): String;
     Const myWhiteSpace = [#0..#32];
     var I: Integer;
     begin
      Result := '';
      Try
       I := 1;
       while I<=Length(S)do Begin
        if not(S[I]in MyWhiteSpace)then Result := Result + S[I];
        Inc(I,1);
       end;
      Except
       Result := '';
      end;
     end;
begin
   try
   Result := '';
   r := TRegExpr.Create;
   r.Expression := '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$';
   pT := My_Trim(pT);
   if r.Exec(pT) then begin
     for i := 1 to 4 do begin
       J := StrToInt(r.Match[i]);
       if J > 255 then begin
           Result := '';
           Break;
       end else begin
         if Result<>''then Result := Result + '.';
         Result := Result + IntToStr(J);//for delete space and zero on left
       end;
     end;
   end;
   finally
     r.Free;
   end;
end;




More information about the Lazarus mailing list