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. A listing of 21 this program is given in the 22 <a href="pcredemo.html"><b>pcredemo</b></a> 23 documentation. If you do not have a copy of the PCRE distribution, you can save 24 this listing to re-create <i>pcredemo.c</i>. 25 </P> 26 <P> 27 The program compiles the regular expression that is its first argument, and 28 matches it against the subject string in its second argument. No PCRE options 29 are set, and default character tables are used. If matching succeeds, the 30 program outputs the portion of the subject that matched, together with the 31 contents of any captured substrings. 32 </P> 33 <P> 34 If the -g option is given on the command line, the program then goes on to 35 check for further matches of the same regular expression in the same subject 36 string. The logic is a little bit tricky because of the possibility of matching 37 an empty string. Comments in the code explain what is going on. 38 </P> 39 <P> 40 If PCRE is installed in the standard include and library directories for your 41 operating system, you should be able to compile the demonstration program using 42 this command: 43 <pre> 44 gcc -o pcredemo pcredemo.c -lpcre 45 </pre> 46 If PCRE is installed elsewhere, you may need to add additional options to the 47 command 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 49 like this: 50 <pre> 51 gcc -o pcredemo -I/usr/local/include pcredemo.c -L/usr/local/lib -lpcre 52 </pre> 53 In a Windows environment, if you want to statically link the program against a 54 non-dll <b>pcre.a</b> file, you must uncomment the line that defines PCRE_STATIC 55 before 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> 60 Once you have compiled and linked the demonstration program, you can run simple 61 tests 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> 66 Note that there is a much more comprehensive test program, called 67 <a href="pcretest.html"><b>pcretest</b>,</a> 68 which supports many more facilities for testing regular expressions and the 69 PCRE library. The 70 <a href="pcredemo.html"><b>pcredemo</b></a> 71 program is provided as a simple coding example. 72 </P> 73 <P> 74 If you try to run 75 <a href="pcredemo.html"><b>pcredemo</b></a> 76 when PCRE is not installed in the standard library directory, you may get an 77 error 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> 81 This is caused by the way shared library support works on those systems. You 82 need 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> 89 AUTHOR 90 </b><br> 91 <P> 92 Philip Hazel 93 <br> 94 University Computing Service 95 <br> 96 Cambridge CB2 3QH, England. 97 <br> 98 </P> 99 <br><b> 100 REVISION 101 </b><br> 102 <P> 103 Last updated: 17 November 2010 104 <br> 105 Copyright © 1997-2010 University of Cambridge. 106 <br> 107 <p> 108 Return to the <a href="index.html">PCRE index page</a>. 109 </p> 110