[fpc-pascal] RegExpr - replace
Marcos Douglas
md at delfire.net
Sun Sep 7 16:11:57 CEST 2014
On Sun, Sep 7, 2014 at 9:36 AM, leledumbo <leledumbo_cool at yahoo.co.id> wrote:
>
> If I'm not mistaken what you want:
>
> {$mode objfpc}{$H+}
> uses
> RegExpr;
> var
> InputStr: string;
> r: TRegExpr;
> begin
> r:= TRegExpr.Create;
> try
> InputStr := ' 28/07/2014 </3604669/trabalho-28-07-2014-pg-1> ';
> r.Expression := '(\/)([0-9]+)(\/.*?pg\-)(\d+).*?"';
> r.Exec(InputStr);
> WriteLn(r.Substitute('$1$4$3$2'));
> finally
> r.Free;
> end;
> end.
>
> should do it.
UAU!
Didn't worked but you gave me the answer because this worked:
{$mode objfpc}{$H+}
uses
RegExpr;
var
InputStr: string;
r: TRegExpr;
begin
r:= TRegExpr.Create;
try
InputStr := '<a href="/3604669/trabalho-28-07-2014-pg-1"
title="Página 1, pg 1, 28/07/2014"> 28/07/2014 </a>';
r.Expression := '(\/)([0-9]+)(\/.*?pg\-)(\d+)(.*?)"';
r.Exec(InputStr);
ShowMessage(r.Substitute('$1#p1$3#p2$5'));
finally
r.Free;
end;
end;
I finished this task yesterday making a new method for my own TRegExpr
but your tip is more elegant, thank you!
--
Marcos Douglas
More information about the fpc-pascal
mailing list