Perl Compatible Regular Expressions for Xbase++


The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. This DLL makes the powerful regular expression technology available for Xbase++. There is a sophisticated object oriented API as well as an easy to use functional interface available. This API-Implementation is further called pcre2. The syntax and semantics of the regular expressions that are supported by PCRE2 are described in detail here.

PCRE2 DLL API

Object oriented API

cRegexp()

Class for pcre2.

class methods

:new( <sPattern> ) Creates an instance of the cRegexp class. If the parameter <sPattern> is given the pattern is compiled immediately. This has the same effect as: oRe := cRegexp():new() followed by oRe:compile( <sPattern> ).

:compile( <sPattern> ) compiles the <sPattern> for further matching. An empty string is returned on success, an errormessage on failure. By calling :match() with different subjects they can be matched without compiling the pattern for every match, which boosts performance for repeating matches with the same pattern.

:clear() The method :clear() is part of the life cycle of the cRegexp-object and releases the system resources requested using the method :compile(). The object remains in existence and can later be reused with :compile() again. The :clear() should be called before a block which contains a compiled cRegexp-object is left to avoid memory leakage.

:match( <sSubject> ) Matches the given <sSubject> with the compiled pattern and returns an array of strings on matching success and an empty array on mismatch. The first array element is the complete maching part of <sSubject>. If there are bracket-catching subelements in the pattern, these substrings go into the following arrayelements accordingly.

:select( <aSubject> ) Matches all elements of the array <aSubject> with the compiled pattern and returns an array consisting only of the matching elements from <aSubject>.

:error() Returns the last error from compile() or new() and an empty string on success.

:version() Returns the used PCRE2 version as a string.

Functional API

regexpmatch( <sPattern>, <sSubject> ) Matches <sSubject> against <sPattern> and returns the same array as described in :match(). The whole livecycle of the cRegexp-object (new, compile, match, clear) is handled by the function - this is easy to use.

Example

  #pragma library( "pcre2.lib" )

  oHello := cRegexp():new( "hello (\w*)" )
  aSubs := oHello:match( "say hello Foo you fool" )
  sGreeted := aSubs[2] // <- "Foo"

  aSubs := regexpmatch( "hello (\w*)", "say hello Foo you fool" )
  sGreeted := aSubs[2] // <- "Foo"

Deployment

Files

pcre2.dll The DLL with the pcre2-routines from https://pcre.org/. This file must be installed in <Alaska 2.0 base directory>\xpp20\lib, <Alaska 2.0 base directory> usually is "C:\Program Files\Alaska Software". This file also must be delivered along with the applications runtime dlls as described in Xbase++ docs "Deployment of Xbase++ applications": "For simplicity, an Xbase++ application should be deployed with all the runtime files contained in the xpp<xx>\runtime folder". This file contains the BSD-licensed code from pcre.org and can be freely distributed.

pcre2.lib The import library is needed by the Xbase++-linker ALINK.EXE and should be also installed in <Alaska 2.0 base directory>\xpp20\lib. This file is only needed at link-time.

pcre2.obj This is the C-API-interface from Xbase to pcre2 and is needed by the Xbase++-linker to include into the application. It should be copied into the project-directory and added to the projects target with "Add existing file ...". Since it is included in the application this file is only needed at link-time of the application.

Copyright

The interface pcre2.obj is Copyright Axel Reinhold
The library pcre2.dll contains PCRE2 from http://pcre.org/ with BSD license.

Demo version

The Demoversion <arxpcre2d.10.x.y.z-x86.zip> returns only 400 matches. After that "no match" is always returned. Ask for a unlimited licensed version of pcre2 by mail to axel@toarx.de.

Disclaimer

This interface library is supplied without any warranties of any kind, and you use it entirely at your own risk.

Note: Advanced Web 2.0 hosting small with power

Menü