我现在是硬编码.但循环太多了..
procedure TForm1.Button2Click(Sender: TObject);
var
Result: Boolean;
strText, s1, s2, s3, s4,s: string;
iStart, iEnd, i, j, k, l, m, n, iPos: integer;
bFound: Boolean;
begin
Result := False;
strText:='sefs92345kmzxcasdfl;;asdasfbgtrthrthrth202.103.628.76oplasasdhjghsdAm,SDSFGNNZASDFB111.345.sxdsdsddf202.103.224.68zsdffghntghtrtrt102.103.23.88sasSDG90234';
for i := 1 to length(strText) do if strText in ['1'..'9'] then
begin
iStart := i;
for j := i to i + 3 do if strText[j] = '.' then
begin
bFound := True;
for n := i to j - 1 do if not (strText[n] in ['0'..'9']) then
begin
bFound := False;
break;
end;
if not bFound then Continue;
s1 := Copy(strText, i, j - i);
if strText[j + 1] in ['1'..'9'] then
begin
for k := j + 1 to j + 4 do if strText[k] = '.' then
begin
bFound := True;
for n := j + 1 to k - 1 do if not (strText[n] in ['0'..'9']) then
begin
bFound := False;
break;
end;
if not bFound then Continue;
s2 := Copy(strText, j + 1, k - 1 - j);
if strText[k + 1] in ['1'..'9'] then
begin
for l := k + 1 to k + 4 do if strText[l] = '.' then
begin
bFound := True;
for n := k + 1 to l - 1 do if not (strText[n] in ['0'..'9']) then
begin
bFound := False;
break;
end;
if not bFound then Continue;
s3 := Copy(strText, k + 1, l - 1 - k);
if strText[l + 1] in ['1'..'9'] then
begin
for m := l + 1 to l + 4 do
if not (strText[m] in ['0'..'9']) then break;
bFound := True;
for n := l + 1 to m - 1 do if not (strText[n] in ['0'..'9']) then
begin
bFound := False;
break;
end;
if not bFound then Continue;
s4 := Copy(strText, l + 1, m - 1 - l);
if (StrToIntDef(s1,256)>255) or
(StrToIntDef(s2,256)>255) or
(StrToIntDef(s3,256)>255) or
(StrToIntDef(s4,256)>255) then
Continue else
begin
s:=copy(strText, iStart, m - iStart);
ShowMessage('Found:'+s);
exit;
end;
end;
end;
end;
end;
end;
end;
end;
ShowMessage('finish');
end;