RegexObj := TRegExpr.Create; RegexObj.Expression := '123456$'; reset(tfIn); while not eof(tfIn) do begin readln(tfIn, s); if RegexObj.Exec(s) then counter2:=counter2+1; counter:=counter+1; end;