| 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>
|
| 8 |
Return to the <a href="index.html">PCRE index page</a>.
|
| 9 |
</p>
|
| 10 |
<p>
|
| 11 |
This page is part of the PCRE HTML documentation. It was generated automatically
|
| 12 |
from the original man page. If there is any nonsense in it, please consult the
|
| 13 |
man page, in case the conversion went wrong.
|
| 14 |
<br>
|
| 15 |
<br><b>
|
| 16 |
PCRE SAMPLE PROGRAM
|
| 17 |
</b><br>
|
| 18 |
<P>
|
| 19 |
A simple, complete demonstration program, to get you started with using PCRE,
|
| 20 |
is supplied in the file <i>pcredemo.c</i> in the PCRE distribution.
|
| 21 |
</P>
|
| 22 |
<P>
|
| 23 |
The program compiles the regular expression that is its first argument, and
|
| 24 |
matches it against the subject string in its second argument. No PCRE options
|
| 25 |
are set, and default character tables are used. If matching succeeds, the
|
| 26 |
program outputs the portion of the subject that matched, together with the
|
| 27 |
contents of any captured substrings.
|
| 28 |
</P>
|
| 29 |
<P>
|
| 30 |
If the -g option is given on the command line, the program then goes on to
|
| 31 |
check for further matches of the same regular expression in the same subject
|
| 32 |
string. The logic is a little bit tricky because of the possibility of matching
|
| 33 |
an empty string. Comments in the code explain what is going on.
|
| 34 |
</P>
|
| 35 |
<P>
|
| 36 |
If PCRE is installed in the standard include and library directories for your
|
| 37 |
system, you should be able to compile the demonstration program using this
|
| 38 |
command:
|
| 39 |
<pre>
|
| 40 |
gcc -o pcredemo pcredemo.c -lpcre
|
| 41 |
</pre>
|
| 42 |
If PCRE is installed elsewhere, you may need to add additional options to the
|
| 43 |
command line. For example, on a Unix-like system that has PCRE installed in
|
| 44 |
<i>/usr/local</i>, you can compile the demonstration program using a command
|
| 45 |
like this:
|
| 46 |
<pre>
|
| 47 |
gcc -o pcredemo -I/usr/local/include pcredemo.c -L/usr/local/lib -lpcre
|
| 48 |
</pre>
|
| 49 |
Once you have compiled the demonstration program, you can run simple tests like
|
| 50 |
this:
|
| 51 |
<pre>
|
| 52 |
./pcredemo 'cat|dog' 'the cat sat on the mat'
|
| 53 |
./pcredemo -g 'cat|dog' 'the dog sat on the cat'
|
| 54 |
</pre>
|
| 55 |
Note that there is a much more comprehensive test program, called
|
| 56 |
<a href="pcretest.html"><b>pcretest</b>,</a>
|
| 57 |
which supports many more facilities for testing regular expressions and the
|
| 58 |
PCRE library. The <b>pcredemo</b> program is provided as a simple coding
|
| 59 |
example.
|
| 60 |
</P>
|
| 61 |
<P>
|
| 62 |
On some operating systems (e.g. Solaris), when PCRE is not installed in the
|
| 63 |
standard library directory, you may get an error like this when you try to run
|
| 64 |
<b>pcredemo</b>:
|
| 65 |
<pre>
|
| 66 |
ld.so.1: a.out: fatal: libpcre.so.0: open failed: No such file or directory
|
| 67 |
</pre>
|
| 68 |
This is caused by the way shared library support works on those systems. You
|
| 69 |
need to add
|
| 70 |
<pre>
|
| 71 |
-R/usr/local/lib
|
| 72 |
</pre>
|
| 73 |
(for example) to the compile command to get round this problem.
|
| 74 |
</P>
|
| 75 |
<P>
|
| 76 |
Last updated: 09 September 2004
|
| 77 |
<br>
|
| 78 |
Copyright © 1997-2004 University of Cambridge.
|
| 79 |
<p>
|
| 80 |
Return to the <a href="index.html">PCRE index page</a>.
|
| 81 |
</p>
|