1<html> 2<head> 3<title>pcresample specification</title> 4</head> 5<body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB"> 6<h1>pcresample man page</h1> 7<p> 8Return to the <a href="index.html">PCRE index page</a>. 9</p> 10<p> 11This page is part of the PCRE HTML documentation. It was generated automatically 12from the original man page. If there is any nonsense in it, please consult the 13man page, in case the conversion went wrong. 14<br> 15<br><b> 16PCRE SAMPLE PROGRAM 17</b><br> 18<P> 19A simple, complete demonstration program, to get you started with using PCRE, 20is supplied in the file <i>pcredemo.c</i> in the PCRE distribution. A listing of 21this program is given in the 22<a href="pcredemo.html"><b>pcredemo</b></a> 23documentation. If you do not have a copy of the PCRE distribution, you can save 24this listing to re-create <i>pcredemo.c</i>. 25</P> 26<P> 27The program compiles the regular expression that is its first argument, and 28matches it against the subject string in its second argument. No PCRE options 29are set, and default character tables are used. If matching succeeds, the 30program outputs the portion of the subject that matched, together with the 31contents of any captured substrings. 32</P> 33<P> 34If the -g option is given on the command line, the program then goes on to 35check for further matches of the same regular expression in the same subject 36string. The logic is a little bit tricky because of the possibility of matching 37an empty string. Comments in the code explain what is going on. 38</P> 39<P> 40If PCRE is installed in the standard include and library directories for your 41operating system, you should be able to compile the demonstration program using 42this command: 43<pre> 44 gcc -o pcredemo pcredemo.c -lpcre 45</pre> 46If PCRE is installed elsewhere, you may need to add additional options to the 47command line. For example, on a Unix-like system that has PCRE installed in 48<i>/usr/local</i>, you can compile the demonstration program using a command 49like this: 50<pre> 51 gcc -o pcredemo -I/usr/local/include pcredemo.c -L/usr/local/lib -lpcre 52</pre> 53In a Windows environment, if you want to statically link the program against a 54non-dll <b>pcre.a</b> file, you must uncomment the line that defines PCRE_STATIC 55before including <b>pcre.h</b>, because otherwise the <b>pcre_malloc()</b> and 56<b>pcre_free()</b> exported functions will be declared 57<b>__declspec(dllimport)</b>, with unwanted results. 58</P> 59<P> 60Once you have compiled and linked the demonstration program, you can run simple 61tests like this: 62<pre> 63 ./pcredemo 'cat|dog' 'the cat sat on the mat' 64 ./pcredemo -g 'cat|dog' 'the dog sat on the cat' 65</pre> 66Note that there is a much more comprehensive test program, called 67<a href="pcretest.html"><b>pcretest</b>,</a> 68which supports many more facilities for testing regular expressions and the 69PCRE library. The 70<a href="pcredemo.html"><b>pcredemo</b></a> 71program is provided as a simple coding example. 72</P> 73<P> 74If you try to run 75<a href="pcredemo.html"><b>pcredemo</b></a> 76when PCRE is not installed in the standard library directory, you may get an 77error like this on some operating systems (e.g. Solaris): 78<pre> 79 ld.so.1: a.out: fatal: libpcre.so.0: open failed: No such file or directory 80</pre> 81This is caused by the way shared library support works on those systems. You 82need to add 83<pre> 84 -R/usr/local/lib 85</pre> 86(for example) to the compile command to get round this problem. 87</P> 88<br><b> 89AUTHOR 90</b><br> 91<P> 92Philip Hazel 93<br> 94University Computing Service 95<br> 96Cambridge CB2 3QH, England. 97<br> 98</P> 99<br><b> 100REVISION 101</b><br> 102<P> 103Last updated: 17 November 2010 104<br> 105Copyright © 1997-2010 University of Cambridge. 106<br> 107<p> 108Return to the <a href="index.html">PCRE index page</a>. 109</p> 110