|
#1
|
|||
|
|||
спарсить ссылку
Помогите спарсить ссылку.
Код:
http://cfire.mail.ru/images/userbars/707/37fc5a893924ef0f39b33bd1db321c9f/389x80.jpg Там где 707/37fc5a893924ef0f39b33bd1db321c9f, могут быть разные цифры. Не получается подключить regexp. Можно как-то подругому ? Сама регулярка такая: Код:
http://cfire.mail.ru/images/userbars/(.+)/389x80.jpg Но в какой фк-ции её использовать я не знаю. |
#2
|
||||
|
||||
вроде ф-ия Exec
— Как тебя понимать? — Понимать меня не обязательно. Обязательно меня любить и кормить вовремя. На Delphi, увы, больше не программирую. Рекомендуемая литература по программированию |
#3
|
|||
|
|||
не то..(лала 10 пукаф)
|
#4
|
||||
|
||||
Модуль:
Код:
unit RegExp; interface uses {Standart} SysUtils, Windows, Classes, {Special} PerlRegEx; type TRegExp = class private FRegExp: TPerlRegEx; protected property RegExp: TPerlRegEx read FRegExp write FRegExp; public function Match(Exp, Text: UTF8String): UTF8String; overload; function Match(Exp, Text: UTF8String; Group: Integer): UTF8String; overload; procedure Match(Exp, Text: UTF8String; Results: TStrings); overload; function Replace(Exp, Text, Replacement: UTF8String): UTF8String; function Count: Integer; function Offset(Group: Integer): Integer; function Length(Group: Integer): Integer; function Result(Group: Integer): UTF8String; constructor Create; destructor Destroy; override; end; implementation { TRegExp } constructor TRegExp.Create; begin inherited Create; FRegExp := TPerlRegEx.Create; end; destructor TRegExp.Destroy; begin FreeAndNil(FRegExp); inherited Destroy; end; function TRegExp.Match(Exp, Text: UTF8String): UTF8String; begin Result := ''; RegExp.Subject := Text; RegExp.RegEx := Exp; if RegExp.Match then Result := RegExp.MatchedText; end; function TRegExp.Match(Exp, Text: UTF8String; Group: Integer): UTF8String; begin Result := ''; RegExp.Subject := Text; RegExp.RegEx := Exp; if RegExp.Match then Result := RegExp.Groups[Group]; end; procedure TRegExp.Match(Exp, Text: UTF8String; Results: TStrings); var i: Integer; begin Results.Clear; RegExp.Subject := Text; RegExp.RegEx := Exp; if RegExp.Match then repeat Results.Add(RegExp.MatchedText); until not RegExp.MatchAgain; end; function TRegExp.Replace(Exp, Text, Replacement: UTF8String): UTF8String; begin Result := ''; RegExp.Subject := Text; RegExp.RegEx := Exp; RegExp.Replacement := Replacement; if RegExp.ReplaceAll then Result := RegExp.Subject; end; function TRegExp.Count: Integer; begin Result := RegExp.GroupCount; end; function TRegExp.Offset(Group: Integer): Integer; begin Result := RegExp.GroupOffsets[Group]; end; function TRegExp.Length(Group: Integer): Integer; begin Result := RegExp.GroupLengths[Group]; end; function TRegExp.Result(Group: Integer): UTF8String; begin Result := RegExp.Groups[Group]; end; end. Использование: Код:
var RegExp: TRegExp; Pattern: string; begin RegExp := TRegExp.Create; try Pattern := 'http\:\/\/cfire\.mail\.ru\/images\/userbars\/(.+?)\/389x80\.jpg'; TempString := Utf8ToAnsi(RegExp.Match(AnsiToUtf8(Pattern), AnsiToUtf8(HTML.Text), 1)); . . . Как-то так. 00110001 00101100 00110110 00110001 00111000 00110000 00110011 00110011 00111001 00111000 00111000 00110111 00110100 00111001 00111000 00111001 00110100 00111000 00110100 00111000 00110010 00110000 00110100 00110101 00111000 00110110 00111000 00110011 00110100 00110011 00110110 00110101 00110110 Последний раз редактировалось ~TB~, 15.09.2012 в 22:11. |
#5
|
||||
|
||||
Еще одна тема?
Код:
//http://cfire.mail.ru/images/userbars/707/37fc5a893924ef0f39b33bd1db321c9f/389x80.jpg //38 номер начала строки //48 количество ненужных символов memo1.Lines.add(copy(s,38,length(s)-48)); П.с.: Что дальше будем делать? Для "hello world" писать: http://www.phppatterns.com/docs/desi...ld_in_patterns Помогаю платно. Помогаю иногда бесплатно. Последний раз редактировалось @Rafa3L, 16.09.2012 в 19:15. |
#6
|
||||
|
||||
Код:
var S:String; begin S:='http://cfire.mail.ru/images/userbars/707/37fc5a893924ef0f39b33bd1db321c9f/389x80.jpg'; ShowMessage(Copy(S,Length('http://cfire.mail.ru/images/userbars/')+1,Pos('/389x80.jpg',S)-Length('http://cfire.mail.ru/images/userbars/')-1)); end; Код сырец |