[fpc-pascal] PCRE

S. Fisher expandafter at yahoo.com
Thu Nov 8 03:00:40 CET 2007


--- L <L at z505.com> wrote:


> > - JCL is not in a runnable state for most FPC targets.
> > - translated Delphi headers are typically not clean for cross platform
> > (most
> >   notably 64-bit) use.
> 
> Jeff's unit may have been, for all you know, which is the unit that I
> supplied a
> uRL to in my first email. Which I cannot download, and am waiting for Jeff
> to
> reply. In the mean time, S. Fisher has already got a unit working while we
> were
> yapping.
> 
> L505

For everbody who wants pcre, here's how I got it working.
>From http://www.renatomancuso.com/software/dpcre/dpcre.htm,
download "PCRE 6.7 DLL".

To the file PCRE.pas, apply the attached patch file.  If you don't,
there will be errors during compiling.

I couldn't find any documentation.  This quick and dirty little
program may help.

{$mode delphi}


uses pcre;

function count_matches( const needle, haystack: ansistring ):longint;
var
  rx : iregex;
  capture: imatch;
  where: longint;
begin
  rx := regexCreate( needle ); 
  result := 0;
  where := 0;
  repeat
    capture := rx.match( haystack, where );
    if not capture.success then  break;
    inc( result );
    where := capture.groups[0].index + capture.groups[0].length;
  until false;
end;


var

  rx : iregex;
  capdata: imatch;
  md : idfamatchCollection;

  str: ansistring;
  i : integer;

begin
  str := 'Come back, Mac.';

  rx := regexCreate( '(\w*)a(\w*)' ); 

  capdata := rx.match( str );
  if capdata.success then
  begin
    writeln( 'found' );
    writeln( capdata.groups.count, ' captures' );
    for i:= 0 to capdata.groups.count - 1 do
      writeln( ' ', capdata.groups[i].index, ' ', capdata.groups[i].length,
        '  value: ', capdata.groups[i].value );
    writeln;
  end
  else
    writeln( 'not' );


  writeln;
  md := rx.dfaMatch( str );
  writeln( 'count: ', md.count );

  if md.count > 0 then
  begin
    writeln( 'dfamatch won' );
    writeln( md[0].index, ' ', md[0].length,' ', md[0].value );

  end
  else
    writeln( 'dfamatch failed' );

  writeln;
  writeln('counting matches');
  writeln( count_matches( 't', 'try to do it' ));
end.



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dif
Type: application/octet-stream
Size: 546 bytes
Desc: 313907380-dif
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20071107/ce718f7f/attachment.obj>


More information about the fpc-pascal mailing list