Version Compatibility

Some operating systems ship with PCRE Version 3 or 4. As of this writing, Version 5 is available for those who wish to compile a private copy. Given the slight differences between them—most notably, the work area size—your code is more robust if it detects the version at buildtime or runtime and behaves accordingly. PCRE includes tools to help you do this. From the command line, call: $ pcre-config --version to retrieve the system's installed (runtime) version. From code, test against the preprocessor constants PCRE_MAJOR (library major version), PCRE_MINOR (minor version), and PCRE_DATE (source-code date). The sample code uses these constants to size a regexp's work area:
const int WORK_AREA_SIZE = (
  3 == PCRE_MAJOR
    ?
  ( 3 * ( totalMatches ) )
    :
  ( 3 * ( 1 + totalMatches ) )
) ;
int workArea[ WORK_AREA_SIZE ] ;

You can also call pcre_version() at runtime to print the full API revision and source-code date.