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

David Copeland david.copeland at jsidata.ca
Fri Oct 25 14:01:36 CEST 2013


I see that the starting IP  can have imbedded spaces. Trim only removes
leading and trailing space. I believe the DelSpace function will remove
all space.

Dave.

On 10/25/2013 07:31 AM, FreeMan wrote:
> 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;
>
> -- 
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>






More information about the Lazarus mailing list