Italian community of Lazarus and Free Pascal

Programmazione => Generale => Topic aperto da: xinyiman - Febbraio 07, 2015, 03:13:18 pm

Titolo: Espressioni regolari
Inserito da: xinyiman - Febbraio 07, 2015, 03:13:18 pm
Ragazzi, tempo fa avevo già fatto (ma non trovo) del codice che permetteva di estrarre da un file tutti gli url e tutte le mail. Ci ho sbattuto un po la testa, ma non mi funziona. Chi mi aiuta?

Codice: [Seleziona]
function TForm1.GetUrl(sito: string): string;
var
   CodicePag: string;
   regex: TRegExpr;
   i: integer;
begin
  codicepag:='http//www.lazaruspascal.it       http://www.liuheschool.com    ';
  regex:=TRegExpr.Create;
  try
    regex.Expression:='\b(?:(?:https?|ftp|file)://|www\.|ftp\.)[-A-Z0-9+&@#/%=~_|$?!:,.]*[A-Z0-9+&@#/%=~_|$]';
    if RegEx.Exec(CodicePag) then
    begin
        for i:=1 to regex.SubExprMatchCount do
          Memo1.Append(regex.Match[i]);
    end;
  finally
    regex.Free;
  end;

  memo1.Append('finito') ;
end;