PCRE Delphi Interface

Perl Compatible Regular Expression library in Delphi!

This is a Delphi class to simplify the use of the pcre library.

Pcre is a powerful regular expression library written by Philip Hazel ph10@cam.ac.uk that is compatible with the one that Perl uses, and that many people already knows.

My little work was compling the pcre lib to make a .obj and build the TRegex class interface.

For compile the pcre library I used the Borland C++ free compiler. I have also extracted from the bcc library some .obj files needed by Delphi to build your pcre apps. The small fixes needed to the original source code are listed in diff.txt.

Properties and functions

property Pattern: string
Regular expression to match or search
property Options: integer
Options flags, eg: caseless, exended, etc..
property Sub[Idx : integer]: string
returns the Idx-nth subexpression if grouping is used starting at index 1. Sub[0] returns the entire substring matched.
property NumSubs: integer
returns the number of subexpressions matched
property Found : boolean
true if successful match
function match( const sText: string ): integer
match sText with given Pattern

For more information please read the man page of the original pcre library.

Sample Usage

procedure TForm1.doregex;
var
  Reg : TRegex;
  i : integer;
  Res  : integer;
begin
  Reg := TRegex.create;
  Reg.Pattern := EditRegex.text;
  Res := Reg.match(EditText.text)

  EditPos.text := IntToStr(Res);

  ListBoxMatch.items.clear;
  for i := 1 to Reg.NumSubs do
    ListBoxMatch.items.add(Reg[i]);

  Reg.free;
end;

Installation

Extract the contents of bcc-obj.zip and dpcre.zip in a directory listed in your Delphi search path.

Package Contents

bcc-obj.zip
runtime library objects needed by pcre
pcre-3.1 for Delphi.zip
pcre version 3.1 source files needed to build pcre.obj
dpcre.zip
Delphi pcre interface modules
demo.zip
very simple demo (console app)

Copyright

PCRE Delphi interface is free. I would be grateful to anyone that will send me suggestions for improvements or bug reports.

PCRE library is written by: Philip Hazel ph10@cam.ac.uk, Copyright (c) 1998 University of Cambridge, and is subject to the following restrictions:


Permission is granted to anyone to use this software for any purpose on any computer system, and to redistribute it freely, subject to the following restrictions:

1. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2. The origin of this software must not be misrepresented, either by explicit claim or by omission.

3. Altered versions must be plainly marked as such, and must not be misrepresented as being the original software.


Download