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
| // uses System.RegularExpressions;
procedure TForm1.Button3Click(Sender: TObject);
const
randomstring = '98396248'; //Résultat attendu : 324
regexstring = '([3])[6-9]*([0-5][0-9])|([0-2][0-9]{2})';
var
regex: TRegEx;
match: TMatchCollection;
groupe: TGroupCollection;
i, j: Integer;
stmp: string;
begin
regex := TRegEx.Create(regexstring);
match := regex.Matches(randomstring);
if match.Count > 0 then
begin
i := 0; // Le premier résultat
groupe := match.Item[i].Groups;
stmp := '';
{ 3 groupes : 0 Full, 1 : Grp 1, 2 : Grp 2 }
for j := 1 to groupe.Count - 1 do
stmp := stmp + groupe.Item[j].Value;
stmp := randomstring + '->' + stmp;
Memo1.Lines.Add(stmp)
end;
end; |