/[pcre]/code/trunk/doc/pcreapi.3
ViewVC logotype

Diff of /code/trunk/doc/pcreapi.3

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 71 by nigel, Sat Feb 24 21:40:24 2007 UTC revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC
# Line 1  Line 1 
1  .TH PCRE 3  .TH PCREAPI 3
2  .SH NAME  .SH NAME
3  PCRE - Perl-compatible regular expressions  PCRE - Perl-compatible regular expressions
4  .SH SYNOPSIS OF PCRE API  .SH "PCRE NATIVE API"
5  .rs  .rs
6  .sp  .sp
7  .B #include <pcre.h>  .B #include <pcre.h>
8  .PP  .PP
9  .SM  .SM
10  .br  .br
11  .B pcre *pcre_compile(const char *\fIpattern\fR, int \fIoptions\fR,  .B pcre *pcre_compile(const char *\fIpattern\fP, int \fIoptions\fP,
12  .ti +5n  .ti +5n
13  .B const char **\fIerrptr\fR, int *\fIerroffset\fR,  .B const char **\fIerrptr\fP, int *\fIerroffset\fP,
14  .ti +5n  .ti +5n
15  .B const unsigned char *\fItableptr\fR);  .B const unsigned char *\fItableptr\fP);
16  .PP  .PP
17  .br  .br
18  .B pcre_extra *pcre_study(const pcre *\fIcode\fR, int \fIoptions\fR,  .B pcre *pcre_compile2(const char *\fIpattern\fP, int \fIoptions\fP,
19  .ti +5n  .ti +5n
20  .B const char **\fIerrptr\fR);  .B int *\fIerrorcodeptr\fP,
21    .ti +5n
22    .B const char **\fIerrptr\fP, int *\fIerroffset\fP,
23    .ti +5n
24    .B const unsigned char *\fItableptr\fP);
25    .PP
26    .br
27    .B pcre_extra *pcre_study(const pcre *\fIcode\fP, int \fIoptions\fP,
28    .ti +5n
29    .B const char **\fIerrptr\fP);
30  .PP  .PP
31  .br  .br
32  .B int pcre_exec(const pcre *\fIcode\fR, "const pcre_extra *\fIextra\fR,"  .B int pcre_exec(const pcre *\fIcode\fP, "const pcre_extra *\fIextra\fP,"
33    .ti +5n
34    .B "const char *\fIsubject\fP," int \fIlength\fP, int \fIstartoffset\fP,
35    .ti +5n
36    .B int \fIoptions\fP, int *\fIovector\fP, int \fIovecsize\fP);
37    .PP
38    .br
39    .B int pcre_dfa_exec(const pcre *\fIcode\fP, "const pcre_extra *\fIextra\fP,"
40    .ti +5n
41    .B "const char *\fIsubject\fP," int \fIlength\fP, int \fIstartoffset\fP,
42  .ti +5n  .ti +5n
43  .B "const char *\fIsubject\fR," int \fIlength\fR, int \fIstartoffset\fR,  .B int \fIoptions\fP, int *\fIovector\fP, int \fIovecsize\fP,
44  .ti +5n  .ti +5n
45  .B int \fIoptions\fR, int *\fIovector\fR, int \fIovecsize\fR);  .B int *\fIworkspace\fP, int \fIwscount\fP);
46  .PP  .PP
47  .br  .br
48  .B int pcre_copy_named_substring(const pcre *\fIcode\fR,  .B int pcre_copy_named_substring(const pcre *\fIcode\fP,
49  .ti +5n  .ti +5n
50  .B const char *\fIsubject\fR, int *\fIovector\fR,  .B const char *\fIsubject\fP, int *\fIovector\fP,
51  .ti +5n  .ti +5n
52  .B int \fIstringcount\fR, const char *\fIstringname\fR,  .B int \fIstringcount\fP, const char *\fIstringname\fP,
53  .ti +5n  .ti +5n
54  .B char *\fIbuffer\fR, int \fIbuffersize\fR);  .B char *\fIbuffer\fP, int \fIbuffersize\fP);
55  .PP  .PP
56  .br  .br
57  .B int pcre_copy_substring(const char *\fIsubject\fR, int *\fIovector\fR,  .B int pcre_copy_substring(const char *\fIsubject\fP, int *\fIovector\fP,
58  .ti +5n  .ti +5n
59  .B int \fIstringcount\fR, int \fIstringnumber\fR, char *\fIbuffer\fR,  .B int \fIstringcount\fP, int \fIstringnumber\fP, char *\fIbuffer\fP,
60  .ti +5n  .ti +5n
61  .B int \fIbuffersize\fR);  .B int \fIbuffersize\fP);
62  .PP  .PP
63  .br  .br
64  .B int pcre_get_named_substring(const pcre *\fIcode\fR,  .B int pcre_get_named_substring(const pcre *\fIcode\fP,
65  .ti +5n  .ti +5n
66  .B const char *\fIsubject\fR, int *\fIovector\fR,  .B const char *\fIsubject\fP, int *\fIovector\fP,
67  .ti +5n  .ti +5n
68  .B int \fIstringcount\fR, const char *\fIstringname\fR,  .B int \fIstringcount\fP, const char *\fIstringname\fP,
69  .ti +5n  .ti +5n
70  .B const char **\fIstringptr\fR);  .B const char **\fIstringptr\fP);
71  .PP  .PP
72  .br  .br
73  .B int pcre_get_stringnumber(const pcre *\fIcode\fR,  .B int pcre_get_stringnumber(const pcre *\fIcode\fP,
74  .ti +5n  .ti +5n
75  .B const char *\fIname\fR);  .B const char *\fIname\fP);
76  .PP  .PP
77  .br  .br
78  .B int pcre_get_substring(const char *\fIsubject\fR, int *\fIovector\fR,  .B int pcre_get_substring(const char *\fIsubject\fP, int *\fIovector\fP,
79  .ti +5n  .ti +5n
80  .B int \fIstringcount\fR, int \fIstringnumber\fR,  .B int \fIstringcount\fP, int \fIstringnumber\fP,
81  .ti +5n  .ti +5n
82  .B const char **\fIstringptr\fR);  .B const char **\fIstringptr\fP);
83  .PP  .PP
84  .br  .br
85  .B int pcre_get_substring_list(const char *\fIsubject\fR,  .B int pcre_get_substring_list(const char *\fIsubject\fP,
86  .ti +5n  .ti +5n
87  .B int *\fIovector\fR, int \fIstringcount\fR, "const char ***\fIlistptr\fR);"  .B int *\fIovector\fP, int \fIstringcount\fP, "const char ***\fIlistptr\fP);"
88  .PP  .PP
89  .br  .br
90  .B void pcre_free_substring(const char *\fIstringptr\fR);  .B void pcre_free_substring(const char *\fIstringptr\fP);
91  .PP  .PP
92  .br  .br
93  .B void pcre_free_substring_list(const char **\fIstringptr\fR);  .B void pcre_free_substring_list(const char **\fIstringptr\fP);
94  .PP  .PP
95  .br  .br
96  .B const unsigned char *pcre_maketables(void);  .B const unsigned char *pcre_maketables(void);
97  .PP  .PP
98  .br  .br
99  .B int pcre_fullinfo(const pcre *\fIcode\fR, "const pcre_extra *\fIextra\fR,"  .B int pcre_fullinfo(const pcre *\fIcode\fP, "const pcre_extra *\fIextra\fP,"
100  .ti +5n  .ti +5n
101  .B int \fIwhat\fR, void *\fIwhere\fR);  .B int \fIwhat\fP, void *\fIwhere\fP);
102  .PP  .PP
103  .br  .br
104  .B int pcre_info(const pcre *\fIcode\fR, int *\fIoptptr\fR, int  .B int pcre_info(const pcre *\fIcode\fP, int *\fIoptptr\fP, int
105  .B *\fIfirstcharptr\fR);  .B *\fIfirstcharptr\fP);
106  .PP  .PP
107  .br  .br
108  .B int pcre_config(int \fIwhat\fR, void *\fIwhere\fR);  .B int pcre_refcount(pcre *\fIcode\fP, int \fIadjust\fP);
109    .PP
110    .br
111    .B int pcre_config(int \fIwhat\fP, void *\fIwhere\fP);
112  .PP  .PP
113  .br  .br
114  .B char *pcre_version(void);  .B char *pcre_version(void);
# Line 99  PCRE - Perl-compatible regular expressio Line 120  PCRE - Perl-compatible regular expressio
120  .B void (*pcre_free)(void *);  .B void (*pcre_free)(void *);
121  .PP  .PP
122  .br  .br
123    .B void *(*pcre_stack_malloc)(size_t);
124    .PP
125    .br
126    .B void (*pcre_stack_free)(void *);
127    .PP
128    .br
129  .B int (*pcre_callout)(pcre_callout_block *);  .B int (*pcre_callout)(pcre_callout_block *);
130    .
131  .SH PCRE API  .
132    .SH "PCRE API OVERVIEW"
133  .rs  .rs
134  .sp  .sp
135  PCRE has its own native API, which is described in this document. There is also  PCRE has its own native API, which is described in this document. There is
136  a set of wrapper functions that correspond to the POSIX regular expression API.  also a set of wrapper functions that correspond to the POSIX regular expression
137  These are described in the \fBpcreposix\fR documentation.  API. These are described in the
138    .\" HREF
139  The native API function prototypes are defined in the header file \fBpcre.h\fR,  \fBpcreposix\fP
140  and on Unix systems the library itself is called \fBlibpcre.a\fR, so can be  .\"
141  accessed by adding \fB-lpcre\fR to the command for linking an application which  documentation. Both of these APIs define a set of C function calls. A C++
142  calls it. The header file defines the macros PCRE_MAJOR and PCRE_MINOR to  wrapper is distributed with PCRE. It is documented in the
143  contain the major and minor release numbers for the library. Applications can  .\" HREF
144  use these to include support for different releases.  \fBpcrecpp\fP
145    .\"
146  The functions \fBpcre_compile()\fR, \fBpcre_study()\fR, and \fBpcre_exec()\fR  page.
147  are used for compiling and matching regular expressions. A sample program that  .P
148  demonstrates the simplest way of using them is given in the file  The native API C function prototypes are defined in the header file
149  \fIpcredemo.c\fR. The \fBpcresample\fR documentation describes how to run it.  \fBpcre.h\fP, and on Unix systems the library itself is called \fBlibpcre\fP.
150    It can normally be accessed by adding \fB-lpcre\fP to the command for linking
151  There are convenience functions for extracting captured substrings from a  an application that uses PCRE. The header file defines the macros PCRE_MAJOR
152  matched subject string. They are:  and PCRE_MINOR to contain the major and minor release numbers for the library.
153    Applications can use these to include support for different releases of PCRE.
154    \fBpcre_copy_substring()\fR  .P
155    \fBpcre_copy_named_substring()\fR  The functions \fBpcre_compile()\fP, \fBpcre_compile2()\fP, \fBpcre_study()\fP,
156    \fBpcre_get_substring()\fR  and \fBpcre_exec()\fP are used for compiling and matching regular expressions
157    \fBpcre_get_named_substring()\fR  in a Perl-compatible manner. A sample program that demonstrates the simplest
158    \fBpcre_get_substring_list()\fR  way of using them is provided in the file called \fIpcredemo.c\fP in the source
159    distribution. The
160  \fBpcre_free_substring()\fR and \fBpcre_free_substring_list()\fR are also  .\" HREF
161    \fBpcresample\fP
162    .\"
163    documentation describes how to run it.
164    .P
165    A second matching function, \fBpcre_dfa_exec()\fP, which is not
166    Perl-compatible, is also provided. This uses a different algorithm for the
167    matching. This allows it to find all possible matches (at a given point in the
168    subject), not just one. However, this algorithm does not return captured
169    substrings. A description of the two matching algorithms and their advantages
170    and disadvantages is given in the
171    .\" HREF
172    \fBpcrematching\fP
173    .\"
174    documentation.
175    .P
176    In addition to the main compiling and matching functions, there are convenience
177    functions for extracting captured substrings from a subject string that is
178    matched by \fBpcre_exec()\fP. They are:
179    .sp
180      \fBpcre_copy_substring()\fP
181      \fBpcre_copy_named_substring()\fP
182      \fBpcre_get_substring()\fP
183      \fBpcre_get_named_substring()\fP
184      \fBpcre_get_substring_list()\fP
185      \fBpcre_get_stringnumber()\fP
186    .sp
187    \fBpcre_free_substring()\fP and \fBpcre_free_substring_list()\fP are also
188  provided, to free the memory used for extracted strings.  provided, to free the memory used for extracted strings.
189    .P
190  The function \fBpcre_maketables()\fR is used (optionally) to build a set of  The function \fBpcre_maketables()\fP is used to build a set of character tables
191  character tables in the current locale for passing to \fBpcre_compile()\fR.  in the current locale for passing to \fBpcre_compile()\fP, \fBpcre_exec()\fP,
192    or \fBpcre_dfa_exec()\fP. This is an optional facility that is provided for
193  The function \fBpcre_fullinfo()\fR is used to find out information about a  specialist use. Most commonly, no special tables are passed, in which case
194  compiled pattern; \fBpcre_info()\fR is an obsolete version which returns only  internal tables that are generated when PCRE is built are used.
195    .P
196    The function \fBpcre_fullinfo()\fP is used to find out information about a
197    compiled pattern; \fBpcre_info()\fP is an obsolete version that returns only
198  some of the available information, but is retained for backwards compatibility.  some of the available information, but is retained for backwards compatibility.
199  The function \fBpcre_version()\fR returns a pointer to a string containing the  The function \fBpcre_version()\fP returns a pointer to a string containing the
200  version of PCRE and its date of release.  version of PCRE and its date of release.
201    .P
202  The global variables \fBpcre_malloc\fR and \fBpcre_free\fR initially contain  The function \fBpcre_refcount()\fP maintains a reference count in a data block
203  the entry points of the standard \fBmalloc()\fR and \fBfree()\fR functions  containing a compiled pattern. This is provided for the benefit of
204    object-oriented applications.
205    .P
206    The global variables \fBpcre_malloc\fP and \fBpcre_free\fP initially contain
207    the entry points of the standard \fBmalloc()\fP and \fBfree()\fP functions,
208  respectively. PCRE calls the memory management functions via these variables,  respectively. PCRE calls the memory management functions via these variables,
209  so a calling program can replace them if it wishes to intercept the calls. This  so a calling program can replace them if it wishes to intercept the calls. This
210  should be done before calling any PCRE functions.  should be done before calling any PCRE functions.
211    .P
212  The global variable \fBpcre_callout\fR initially contains NULL. It can be set  The global variables \fBpcre_stack_malloc\fP and \fBpcre_stack_free\fP are also
213    indirections to memory management functions. These special functions are used
214    only when PCRE is compiled to use the heap for remembering data, instead of
215    recursive function calls, when running the \fBpcre_exec()\fP function. This is
216    a non-standard way of building PCRE, for use in environments that have limited
217    stacks. Because of the greater use of memory management, it runs more slowly.
218    Separate functions are provided so that special-purpose external code can be
219    used for this case. When used, these functions are always called in a
220    stack-like manner (last obtained, first freed), and always for memory blocks of
221    the same size.
222    .P
223    The global variable \fBpcre_callout\fP initially contains NULL. It can be set
224  by the caller to a "callout" function, which PCRE will then call at specified  by the caller to a "callout" function, which PCRE will then call at specified
225  points during a matching operation. Details are given in the \fBpcrecallout\fR  points during a matching operation. Details are given in the
226    .\" HREF
227    \fBpcrecallout\fP
228    .\"
229  documentation.  documentation.
230    .
231    .
232  .SH MULTITHREADING  .SH MULTITHREADING
233  .rs  .rs
234  .sp  .sp
235  The PCRE functions can be used in multi-threading applications, with the  The PCRE functions can be used in multi-threading applications, with the
236  proviso that the memory management functions pointed to by \fBpcre_malloc\fR  proviso that the memory management functions pointed to by \fBpcre_malloc\fP,
237  and \fBpcre_free\fR, and the callout function pointed to by \fBpcre_callout\fR,  \fBpcre_free\fP, \fBpcre_stack_malloc\fP, and \fBpcre_stack_free\fP, and the
238  are shared by all threads.  callout function pointed to by \fBpcre_callout\fP, are shared by all threads.
239    .P
240  The compiled form of a regular expression is not altered during matching, so  The compiled form of a regular expression is not altered during matching, so
241  the same compiled pattern can safely be used by several threads at once.  the same compiled pattern can safely be used by several threads at once.
242    .
243  .SH CHECKING BUILD-TIME OPTIONS  .
244    .SH "SAVING PRECOMPILED PATTERNS FOR LATER USE"
245  .rs  .rs
246  .sp  .sp
247  .B int pcre_config(int \fIwhat\fR, void *\fIwhere\fR);  The compiled form of a regular expression can be saved and re-used at a later
248    time, possibly by a different program, and even on a host other than the one on
249    which it was compiled. Details are given in the
250    .\" HREF
251    \fBpcreprecompile\fP
252    .\"
253    documentation.
254    .
255    .
256    .SH "CHECKING BUILD-TIME OPTIONS"
257    .rs
258    .sp
259    .B int pcre_config(int \fIwhat\fP, void *\fIwhere\fP);
260  .PP  .PP
261  The function \fBpcre_config()\fR makes it possible for a PCRE client to  The function \fBpcre_config()\fP makes it possible for a PCRE client to
262  discover which optional features have been compiled into the PCRE library. The  discover which optional features have been compiled into the PCRE library. The
263  .\" HREF  .\" HREF
264  \fBpcrebuild\fR  \fBpcrebuild\fP
265  .\"  .\"
266  documentation has more details about these optional features.  documentation has more details about these optional features.
267    .P
268  The first argument for \fBpcre_config()\fR is an integer, specifying which  The first argument for \fBpcre_config()\fP is an integer, specifying which
269  information is required; the second argument is a pointer to a variable into  information is required; the second argument is a pointer to a variable into
270  which the information is placed. The following information is available:  which the information is placed. The following information is available:
271    .sp
272    PCRE_CONFIG_UTF8    PCRE_CONFIG_UTF8
273    .sp
274  The output is an integer that is set to one if UTF-8 support is available;  The output is an integer that is set to one if UTF-8 support is available;
275  otherwise it is set to zero.  otherwise it is set to zero.
276    .sp
277      PCRE_CONFIG_UNICODE_PROPERTIES
278    .sp
279    The output is an integer that is set to one if support for Unicode character
280    properties is available; otherwise it is set to zero.
281    .sp
282    PCRE_CONFIG_NEWLINE    PCRE_CONFIG_NEWLINE
283    .sp
284  The output is an integer that is set to the value of the code that is used for  The output is an integer that is set to the value of the code that is used for
285  the newline character. It is either linefeed (10) or carriage return (13), and  the newline character. It is either linefeed (10) or carriage return (13), and
286  should normally be the standard character for your operating system.  should normally be the standard character for your operating system.
287    .sp
288    PCRE_CONFIG_LINK_SIZE    PCRE_CONFIG_LINK_SIZE
289    .sp
290  The output is an integer that contains the number of bytes used for internal  The output is an integer that contains the number of bytes used for internal
291  linkage in compiled regular expressions. The value is 2, 3, or 4. Larger values  linkage in compiled regular expressions. The value is 2, 3, or 4. Larger values
292  allow larger regular expressions to be compiled, at the expense of slower  allow larger regular expressions to be compiled, at the expense of slower
293  matching. The default value of 2 is sufficient for all but the most massive  matching. The default value of 2 is sufficient for all but the most massive
294  patterns, since it allows the compiled pattern to be up to 64K in size.  patterns, since it allows the compiled pattern to be up to 64K in size.
295    .sp
296    PCRE_CONFIG_POSIX_MALLOC_THRESHOLD    PCRE_CONFIG_POSIX_MALLOC_THRESHOLD
297    .sp
298  The output is an integer that contains the threshold above which the POSIX  The output is an integer that contains the threshold above which the POSIX
299  interface uses \fBmalloc()\fR for output vectors. Further details are given in  interface uses \fBmalloc()\fP for output vectors. Further details are given in
300  the \fBpcreposix\fR documentation.  the
301    .\" HREF
302    \fBpcreposix\fP
303    .\"
304    documentation.
305    .sp
306    PCRE_CONFIG_MATCH_LIMIT    PCRE_CONFIG_MATCH_LIMIT
307    .sp
308  The output is an integer that gives the default limit for the number of  The output is an integer that gives the default limit for the number of
309  internal matching function calls in a \fBpcre_exec()\fR execution. Further  internal matching function calls in a \fBpcre_exec()\fP execution. Further
310  details are given with \fBpcre_exec()\fR below.  details are given with \fBpcre_exec()\fP below.
311    .sp
312  .SH COMPILING A PATTERN    PCRE_CONFIG_MATCH_LIMIT_RECURSION
313  .rs  .sp
314  .sp  The output is an integer that gives the default limit for the depth of
315  .B pcre *pcre_compile(const char *\fIpattern\fR, int \fIoptions\fR,  recursion when calling the internal matching function in a \fBpcre_exec()\fP
316  .ti +5n  execution. Further details are given with \fBpcre_exec()\fP below.
317  .B const char **\fIerrptr\fR, int *\fIerroffset\fR,  .sp
318  .ti +5n    PCRE_CONFIG_STACKRECURSE
319  .B const unsigned char *\fItableptr\fR);  .sp
320  .PP  The output is an integer that is set to one if internal recursion when running
321    \fBpcre_exec()\fP is implemented by recursive function calls that use the stack
322  The function \fBpcre_compile()\fR is called to compile a pattern into an  to remember their state. This is the usual way that PCRE is compiled. The
323  internal form. The pattern is a C string terminated by a binary zero, and  output is zero if PCRE was compiled to use blocks of data on the heap instead
324  is passed in the argument \fIpattern\fR. A pointer to a single block of memory  of recursive function calls. In this case, \fBpcre_stack_malloc\fP and
325  that is obtained via \fBpcre_malloc\fR is returned. This contains the compiled  \fBpcre_stack_free\fP are called to manage memory blocks on the heap, thus
326  code and related data. The \fBpcre\fR type is defined for the returned block;  avoiding the use of the stack.
327  this is a typedef for a structure whose contents are not externally defined. It  .
328  is up to the caller to free the memory when it is no longer required.  .
329    .SH "COMPILING A PATTERN"
330    .rs
331    .sp
332    .B pcre *pcre_compile(const char *\fIpattern\fP, int \fIoptions\fP,
333    .ti +5n
334    .B const char **\fIerrptr\fP, int *\fIerroffset\fP,
335    .ti +5n
336    .B const unsigned char *\fItableptr\fP);
337    .sp
338    .B pcre *pcre_compile2(const char *\fIpattern\fP, int \fIoptions\fP,
339    .ti +5n
340    .B int *\fIerrorcodeptr\fP,
341    .ti +5n
342    .B const char **\fIerrptr\fP, int *\fIerroffset\fP,
343    .ti +5n
344    .B const unsigned char *\fItableptr\fP);
345    .P
346    Either of the functions \fBpcre_compile()\fP or \fBpcre_compile2()\fP can be
347    called to compile a pattern into an internal form. The only difference between
348    the two interfaces is that \fBpcre_compile2()\fP has an additional argument,
349    \fIerrorcodeptr\fP, via which a numerical error code can be returned.
350    .P
351    The pattern is a C string terminated by a binary zero, and is passed in the
352    \fIpattern\fP argument. A pointer to a single block of memory that is obtained
353    via \fBpcre_malloc\fP is returned. This contains the compiled code and related
354    data. The \fBpcre\fP type is defined for the returned block; this is a typedef
355    for a structure whose contents are not externally defined. It is up to the
356    caller to free the memory when it is no longer required.
357    .P
358  Although the compiled code of a PCRE regex is relocatable, that is, it does not  Although the compiled code of a PCRE regex is relocatable, that is, it does not
359  depend on memory location, the complete \fBpcre\fR data block is not  depend on memory location, the complete \fBpcre\fP data block is not
360  fully relocatable, because it contains a copy of the \fItableptr\fR argument,  fully relocatable, because it may contain a copy of the \fItableptr\fP
361  which is an address (see below).  argument, which is an address (see below).
362    .P
363  The \fIoptions\fR argument contains independent bits that affect the  The \fIoptions\fP argument contains independent bits that affect the
364  compilation. It should be zero if no options are required. Some of the options,  compilation. It should be zero if no options are required. The available
365  in particular, those that are compatible with Perl, can also be set and unset  options are described below. Some of them, in particular, those that are
366  from within the pattern (see the detailed description of regular expressions  compatible with Perl, can also be set and unset from within the pattern (see
367  in the \fBpcrepattern\fR documentation). For these options, the contents of the  the detailed description in the
368  \fIoptions\fR argument specifies their initial settings at the start of  .\" HREF
369  compilation and execution. The PCRE_ANCHORED option can be set at the time of  \fBpcrepattern\fP
370  matching as well as at compile time.  .\"
371    documentation). For these options, the contents of the \fIoptions\fP argument
372  If \fIerrptr\fR is NULL, \fBpcre_compile()\fR returns NULL immediately.  specifies their initial settings at the start of compilation and execution. The
373  Otherwise, if compilation of a pattern fails, \fBpcre_compile()\fR returns  PCRE_ANCHORED option can be set at the time of matching as well as at compile
374  NULL, and sets the variable pointed to by \fIerrptr\fR to point to a textual  time.
375  error message. The offset from the start of the pattern to the character where  .P
376  the error was discovered is placed in the variable pointed to by  If \fIerrptr\fP is NULL, \fBpcre_compile()\fP returns NULL immediately.
377  \fIerroffset\fR, which must not be NULL. If it is, an immediate error is given.  Otherwise, if compilation of a pattern fails, \fBpcre_compile()\fP returns
378    NULL, and sets the variable pointed to by \fIerrptr\fP to point to a textual
379  If the final argument, \fItableptr\fR, is NULL, PCRE uses a default set of  error message. This is a static string that is part of the library. You must
380  character tables which are built when it is compiled, using the default C  not try to free it. The offset from the start of the pattern to the character
381  locale. Otherwise, \fItableptr\fR must be the result of a call to  where the error was discovered is placed in the variable pointed to by
382  \fBpcre_maketables()\fR. See the section on locale support below.  \fIerroffset\fP, which must not be NULL. If it is, an immediate error is given.
383    .P
384  This code fragment shows a typical straightforward call to \fBpcre_compile()\fR:  If \fBpcre_compile2()\fP is used instead of \fBpcre_compile()\fP, and the
385    \fIerrorcodeptr\fP argument is not NULL, a non-zero error code number is
386    returned via this argument in the event of an error. This is in addition to the
387    textual error message. Error codes and messages are listed below.
388    .P
389    If the final argument, \fItableptr\fP, is NULL, PCRE uses a default set of
390    character tables that are built when PCRE is compiled, using the default C
391    locale. Otherwise, \fItableptr\fP must be an address that is the result of a
392    call to \fBpcre_maketables()\fP. This value is stored with the compiled
393    pattern, and used again by \fBpcre_exec()\fP, unless another table pointer is
394    passed to it. For more discussion, see the section on locale support below.
395    .P
396    This code fragment shows a typical straightforward call to \fBpcre_compile()\fP:
397    .sp
398    pcre *re;    pcre *re;
399    const char *error;    const char *error;
400    int erroffset;    int erroffset;
# Line 265  This code fragment shows a typical strai Line 404  This code fragment shows a typical strai
404      &error,           /* for error message */      &error,           /* for error message */
405      &erroffset,       /* for error offset */      &erroffset,       /* for error offset */
406      NULL);            /* use default character tables */      NULL);            /* use default character tables */
407    .sp
408  The following option bits are defined:  The following names for option bits are defined in the \fBpcre.h\fP header
409    file:
410    .sp
411    PCRE_ANCHORED    PCRE_ANCHORED
412    .sp
413  If this bit is set, the pattern is forced to be "anchored", that is, it is  If this bit is set, the pattern is forced to be "anchored", that is, it is
414  constrained to match only at the first matching point in the string which is  constrained to match only at the first matching point in the string that is
415  being searched (the "subject string"). This effect can also be achieved by  being searched (the "subject string"). This effect can also be achieved by
416  appropriate constructs in the pattern itself, which is the only way to do it in  appropriate constructs in the pattern itself, which is the only way to do it in
417  Perl.  Perl.
418    .sp
419      PCRE_AUTO_CALLOUT
420    .sp
421    If this bit is set, \fBpcre_compile()\fP automatically inserts callout items,
422    all with number 255, before each pattern item. For discussion of the callout
423    facility, see the
424    .\" HREF
425    \fBpcrecallout\fP
426    .\"
427    documentation.
428    .sp
429    PCRE_CASELESS    PCRE_CASELESS
430    .sp
431  If this bit is set, letters in the pattern match both upper and lower case  If this bit is set, letters in the pattern match both upper and lower case
432  letters. It is equivalent to Perl's /i option, and it can be changed within a  letters. It is equivalent to Perl's /i option, and it can be changed within a
433  pattern by a (?i) option setting.  pattern by a (?i) option setting. In UTF-8 mode, PCRE always understands the
434    concept of case for characters whose values are less than 128, so caseless
435    matching is always possible. For characters with higher values, the concept of
436    case is supported if PCRE is compiled with Unicode property support, but not
437    otherwise. If you want to use caseless matching for characters 128 and above,
438    you must ensure that PCRE is compiled with Unicode property support as well as
439    with UTF-8 support.
440    .sp
441    PCRE_DOLLAR_ENDONLY    PCRE_DOLLAR_ENDONLY
442    .sp
443  If this bit is set, a dollar metacharacter in the pattern matches only at the  If this bit is set, a dollar metacharacter in the pattern matches only at the
444  end of the subject string. Without this option, a dollar also matches  end of the subject string. Without this option, a dollar also matches
445  immediately before the final character if it is a newline (but not before any  immediately before the final character if it is a newline (but not before any
446  other newlines). The PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is  other newlines). The PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is
447  set. There is no equivalent to this option in Perl, and no way to set it within  set. There is no equivalent to this option in Perl, and no way to set it within
448  a pattern.  a pattern.
449    .sp
450    PCRE_DOTALL    PCRE_DOTALL
451    .sp
452  If this bit is set, a dot metacharater in the pattern matches all characters,  If this bit is set, a dot metacharater in the pattern matches all characters,
453  including newlines. Without it, newlines are excluded. This option is  including newlines. Without it, newlines are excluded. This option is
454  equivalent to Perl's /s option, and it can be changed within a pattern by a  equivalent to Perl's /s option, and it can be changed within a pattern by a
455  (?s) option setting. A negative class such as [^a] always matches a newline  (?s) option setting. A negative class such as [^a] always matches a newline
456  character, independent of the setting of this option.  character, independent of the setting of this option.
457    .sp
458    PCRE_EXTENDED    PCRE_EXTENDED
459    .sp
460  If this bit is set, whitespace data characters in the pattern are totally  If this bit is set, whitespace data characters in the pattern are totally
461  ignored except when escaped or inside a character class. Whitespace does not  ignored except when escaped or inside a character class. Whitespace does not
462  include the VT character (code 11). In addition, characters between an  include the VT character (code 11). In addition, characters between an
463  unescaped # outside a character class and the next newline character,  unescaped # outside a character class and the next newline character,
464  inclusive, are also ignored. This is equivalent to Perl's /x option, and it can  inclusive, are also ignored. This is equivalent to Perl's /x option, and it can
465  be changed within a pattern by a (?x) option setting.  be changed within a pattern by a (?x) option setting.
466    .P
467  This option makes it possible to include comments inside complicated patterns.  This option makes it possible to include comments inside complicated patterns.
468  Note, however, that this applies only to data characters. Whitespace characters  Note, however, that this applies only to data characters. Whitespace characters
469  may never appear within special character sequences in a pattern, for example  may never appear within special character sequences in a pattern, for example
470  within the sequence (?( which introduces a conditional subpattern.  within the sequence (?( which introduces a conditional subpattern.
471    .sp
472    PCRE_EXTRA    PCRE_EXTRA
473    .sp
474  This option was invented in order to turn on additional functionality of PCRE  This option was invented in order to turn on additional functionality of PCRE
475  that is incompatible with Perl, but it is currently of very little use. When  that is incompatible with Perl, but it is currently of very little use. When
476  set, any backslash in a pattern that is followed by a letter that has no  set, any backslash in a pattern that is followed by a letter that has no
# Line 323  expansion. By default, as in Perl, a bac Line 479  expansion. By default, as in Perl, a bac
479  special meaning is treated as a literal. There are at present no other features  special meaning is treated as a literal. There are at present no other features
480  controlled by this option. It can also be set by a (?X) option setting within a  controlled by this option. It can also be set by a (?X) option setting within a
481  pattern.  pattern.
482    .sp
483      PCRE_FIRSTLINE
484    .sp
485    If this option is set, an unanchored pattern is required to match before or at
486    the first newline character in the subject string, though the matched text may
487    continue over the newline.
488    .sp
489    PCRE_MULTILINE    PCRE_MULTILINE
490    .sp
491  By default, PCRE treats the subject string as consisting of a single "line" of  By default, PCRE treats the subject string as consisting of a single line of
492  characters (even if it actually contains several newlines). The "start of line"  characters (even if it actually contains newlines). The "start of line"
493  metacharacter (^) matches only at the start of the string, while the "end of  metacharacter (^) matches only at the start of the string, while the "end of
494  line" metacharacter ($) matches only at the end of the string, or before a  line" metacharacter ($) matches only at the end of the string, or before a
495  terminating newline (unless PCRE_DOLLAR_ENDONLY is set). This is the same as  terminating newline (unless PCRE_DOLLAR_ENDONLY is set). This is the same as
496  Perl.  Perl.
497    .P
498  When PCRE_MULTILINE it is set, the "start of line" and "end of line" constructs  When PCRE_MULTILINE it is set, the "start of line" and "end of line" constructs
499  match immediately following or immediately before any newline in the subject  match immediately following or immediately before any newline in the subject
500  string, respectively, as well as at the very start and end. This is equivalent  string, respectively, as well as at the very start and end. This is equivalent
501  to Perl's /m option, and it can be changed within a pattern by a (?m) option  to Perl's /m option, and it can be changed within a pattern by a (?m) option
502  setting. If there are no "\\n" characters in a subject string, or no  setting. If there are no "\en" characters in a subject string, or no
503  occurrences of ^ or $ in a pattern, setting PCRE_MULTILINE has no effect.  occurrences of ^ or $ in a pattern, setting PCRE_MULTILINE has no effect.
504    .sp
505    PCRE_NO_AUTO_CAPTURE    PCRE_NO_AUTO_CAPTURE
506    .sp
507  If this option is set, it disables the use of numbered capturing parentheses in  If this option is set, it disables the use of numbered capturing parentheses in
508  the pattern. Any opening parenthesis that is not followed by ? behaves as if it  the pattern. Any opening parenthesis that is not followed by ? behaves as if it
509  were followed by ?: but named parentheses can still be used for capturing (and  were followed by ?: but named parentheses can still be used for capturing (and
510  they acquire numbers in the usual way). There is no equivalent of this option  they acquire numbers in the usual way). There is no equivalent of this option
511  in Perl.  in Perl.
512    .sp
513    PCRE_UNGREEDY    PCRE_UNGREEDY
514    .sp
515  This option inverts the "greediness" of the quantifiers so that they are not  This option inverts the "greediness" of the quantifiers so that they are not
516  greedy by default, but become greedy if followed by "?". It is not compatible  greedy by default, but become greedy if followed by "?". It is not compatible
517  with Perl. It can also be set by a (?U) option setting within the pattern.  with Perl. It can also be set by a (?U) option setting within the pattern.
518    .sp
519    PCRE_UTF8    PCRE_UTF8
520    .sp
521  This option causes PCRE to regard both the pattern and the subject as strings  This option causes PCRE to regard both the pattern and the subject as strings
522  of UTF-8 characters instead of single-byte character strings. However, it is  of UTF-8 characters instead of single-byte character strings. However, it is
523  available only if PCRE has been built to include UTF-8 support. If not, the use  available only when PCRE is built to include UTF-8 support. If not, the use
524  of this option provokes an error. Details of how this option changes the  of this option provokes an error. Details of how this option changes the
525  behaviour of PCRE are given in the  behaviour of PCRE are given in the
526  .\" HTML <a href="pcre.html#utf8support">  .\" HTML <a href="pcre.html#utf8support">
# Line 367  section on UTF-8 support Line 529  section on UTF-8 support
529  .\"  .\"
530  in the main  in the main
531  .\" HREF  .\" HREF
532  \fBpcre\fR  \fBpcre\fP
533  .\"  .\"
534  page.  page.
535    .sp
536    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
537    .sp
538  When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is  When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is
539  automatically checked. If an invalid UTF-8 sequence of bytes is found,  automatically checked. If an invalid UTF-8 sequence of bytes is found,
540  \fBpcre_compile()\fR returns an error. If you already know that your pattern is  \fBpcre_compile()\fP returns an error. If you already know that your pattern is
541  valid, and you want to skip this check for performance reasons, you can set the  valid, and you want to skip this check for performance reasons, you can set the
542  PCRE_NO_UTF8_CHECK option. When it is set, the effect of passing an invalid  PCRE_NO_UTF8_CHECK option. When it is set, the effect of passing an invalid
543  UTF-8 string as a pattern is undefined. It may cause your program to crash.  UTF-8 string as a pattern is undefined. It may cause your program to crash.
544  Note that there is a similar option for suppressing the checking of subject  Note that this option can also be passed to \fBpcre_exec()\fP and
545  strings passed to \fBpcre_exec()\fR.  \fBpcre_dfa_exec()\fP, to suppress the UTF-8 validity checking of subject
546    strings.
547    .
548  .SH STUDYING A PATTERN  .
549  .rs  .SH "COMPILATION ERROR CODES"
550  .sp  .rs
551  .B pcre_extra *pcre_study(const pcre *\fIcode\fR, int \fIoptions\fR,  .sp
552  .ti +5n  The following table lists the error codes than may be returned by
553  .B const char **\fIerrptr\fR);  \fBpcre_compile2()\fP, along with the error messages that may be returned by
554  .PP  both compiling functions.
555  When a pattern is going to be used several times, it is worth spending more  .sp
556  time analyzing it in order to speed up the time taken for matching. The     0  no error
557  function \fBpcre_study()\fR takes a pointer to a compiled pattern as its first     1  \e at end of pattern
558  argument. If studing the pattern produces additional information that will help     2  \ec at end of pattern
559  speed up matching, \fBpcre_study()\fR returns a pointer to a \fBpcre_extra\fR     3  unrecognized character follows \e
560  block, in which the \fIstudy_data\fR field points to the results of the study.     4  numbers out of order in {} quantifier
561       5  number too big in {} quantifier
562  The returned value from a \fBpcre_study()\fR can be passed directly to     6  missing terminating ] for character class
563  \fBpcre_exec()\fR. However, the \fBpcre_extra\fR block also contains other     7  invalid escape sequence in character class
564       8  range out of order in character class
565       9  nothing to repeat
566      10  operand of unlimited repeat could match the empty string
567      11  internal error: unexpected repeat
568      12  unrecognized character after (?
569      13  POSIX named classes are supported only within a class
570      14  missing )
571      15  reference to non-existent subpattern
572      16  erroffset passed as NULL
573      17  unknown option bit(s) set
574      18  missing ) after comment
575      19  parentheses nested too deeply
576      20  regular expression too large
577      21  failed to get memory
578      22  unmatched parentheses
579      23  internal error: code overflow
580      24  unrecognized character after (?<
581      25  lookbehind assertion is not fixed length
582      26  malformed number after (?(
583      27  conditional group contains more than two branches
584      28  assertion expected after (?(
585      29  (?R or (?digits must be followed by )
586      30  unknown POSIX class name
587      31  POSIX collating elements are not supported
588      32  this version of PCRE is not compiled with PCRE_UTF8 support
589      33  spare error
590      34  character value in \ex{...} sequence is too large
591      35  invalid condition (?(0)
592      36  \eC not allowed in lookbehind assertion
593      37  PCRE does not support \eL, \el, \eN, \eU, or \eu
594      38  number after (?C is > 255
595      39  closing ) for (?C expected
596      40  recursive call could loop indefinitely
597      41  unrecognized character after (?P
598      42  syntax error after (?P
599      43  two named groups have the same name
600      44  invalid UTF-8 string
601      45  support for \eP, \ep, and \eX has not been compiled
602      46  malformed \eP or \ep sequence
603      47  unknown property name after \eP or \ep
604    .
605    .
606    .SH "STUDYING A PATTERN"
607    .rs
608    .sp
609    .B pcre_extra *pcre_study(const pcre *\fIcode\fP, int \fIoptions\fP
610    .ti +5n
611    .B const char **\fIerrptr\fP);
612    .PP
613    If a compiled pattern is going to be used several times, it is worth spending
614    more time analyzing it in order to speed up the time taken for matching. The
615    function \fBpcre_study()\fP takes a pointer to a compiled pattern as its first
616    argument. If studying the pattern produces additional information that will
617    help speed up matching, \fBpcre_study()\fP returns a pointer to a
618    \fBpcre_extra\fP block, in which the \fIstudy_data\fP field points to the
619    results of the study.
620    .P
621    The returned value from \fBpcre_study()\fP can be passed directly to
622    \fBpcre_exec()\fP. However, a \fBpcre_extra\fP block also contains other
623  fields that can be set by the caller before the block is passed; these are  fields that can be set by the caller before the block is passed; these are
624  described below. If studying the pattern does not produce any additional  described
625  information, \fBpcre_study()\fR returns NULL. In that circumstance, if the  .\" HTML <a href="#extradata">
626  calling program wants to pass some of the other fields to \fBpcre_exec()\fR, it  .\" </a>
627  must set up its own \fBpcre_extra\fR block.  below
628    .\"
629  The second argument contains option bits. At present, no options are defined  in the section on matching a pattern.
630  for \fBpcre_study()\fR, and this argument should always be zero.  .P
631    If studying the pattern does not produce any additional information
632  The third argument for \fBpcre_study()\fR is a pointer for an error message. If  \fBpcre_study()\fP returns NULL. In that circumstance, if the calling program
633    wants to pass any of the other fields to \fBpcre_exec()\fP, it must set up its
634    own \fBpcre_extra\fP block.
635    .P
636    The second argument of \fBpcre_study()\fP contains option bits. At present, no
637    options are defined, and this argument should always be zero.
638    .P
639    The third argument for \fBpcre_study()\fP is a pointer for an error message. If
640  studying succeeds (even if no data is returned), the variable it points to is  studying succeeds (even if no data is returned), the variable it points to is
641  set to NULL. Otherwise it points to a textual error message. You should  set to NULL. Otherwise it is set to point to a textual error message. This is a
642  therefore test the error pointer for NULL after calling \fBpcre_study()\fR, to  static string that is part of the library. You must not try to free it. You
643  be sure that it has run successfully.  should test the error pointer for NULL after calling \fBpcre_study()\fP, to be
644    sure that it has run successfully.
645  This is a typical call to \fBpcre_study\fR():  .P
646    This is a typical call to \fBpcre_study\fP():
647    .sp
648    pcre_extra *pe;    pcre_extra *pe;
649    pe = pcre_study(    pe = pcre_study(
650      re,             /* result of pcre_compile() */      re,             /* result of pcre_compile() */
651      0,              /* no options exist */      0,              /* no options exist */
652      &error);        /* set to NULL or points to a message */      &error);        /* set to NULL or points to a message */
653    .sp
654  At present, studying a pattern is useful only for non-anchored patterns that do  At present, studying a pattern is useful only for non-anchored patterns that do
655  not have a single fixed starting character. A bitmap of possible starting  not have a single fixed starting character. A bitmap of possible starting
656  characters is created.  bytes is created.
657    .
658    .
659  .\" HTML <a name="localesupport"></a>  .\" HTML <a name="localesupport"></a>
660  .SH LOCALE SUPPORT  .SH "LOCALE SUPPORT"
661  .rs  .rs
662  .sp  .sp
663  PCRE handles caseless matching, and determines whether characters are letters,  PCRE handles caseless matching, and determines whether characters are letters
664  digits, or whatever, by reference to a set of tables. When running in UTF-8  digits, or whatever, by reference to a set of tables, indexed by character
665  mode, this applies only to characters with codes less than 256. The library  value. When running in UTF-8 mode, this applies only to characters with codes
666  contains a default set of tables that is created in the default C locale when  less than 128. Higher-valued codes never match escapes such as \ew or \ed, but
667  PCRE is compiled. This is used when the final argument of \fBpcre_compile()\fR  can be tested with \ep if PCRE is built with Unicode character property
668  is NULL, and is sufficient for many applications.  support. The use of locales with Unicode is discouraged.
669    .P
670  An alternative set of tables can, however, be supplied. Such tables are built  An internal set of tables is created in the default C locale when PCRE is
671  by calling the \fBpcre_maketables()\fR function, which has no arguments, in the  built. This is used when the final argument of \fBpcre_compile()\fP is NULL,
672  relevant locale. The result can then be passed to \fBpcre_compile()\fR as often  and is sufficient for many applications. An alternative set of tables can,
673  as necessary. For example, to build and use tables that are appropriate for the  however, be supplied. These may be created in a different locale from the
674  French locale (where accented characters with codes greater than 128 are  default. As more and more applications change to using Unicode, the need for
675  treated as letters), the following code could be used:  this locale support is expected to die away.
676    .P
677    setlocale(LC_CTYPE, "fr");  External tables are built by calling the \fBpcre_maketables()\fP function,
678    which has no arguments, in the relevant locale. The result can then be passed
679    to \fBpcre_compile()\fP or \fBpcre_exec()\fP as often as necessary. For
680    example, to build and use tables that are appropriate for the French locale
681    (where accented characters with values greater than 128 are treated as letters),
682    the following code could be used:
683    .sp
684      setlocale(LC_CTYPE, "fr_FR");
685    tables = pcre_maketables();    tables = pcre_maketables();
686    re = pcre_compile(..., tables);    re = pcre_compile(..., tables);
687    .sp
688  The tables are built in memory that is obtained via \fBpcre_malloc\fR. The  When \fBpcre_maketables()\fP runs, the tables are built in memory that is
689  pointer that is passed to \fBpcre_compile\fR is saved with the compiled  obtained via \fBpcre_malloc\fP. It is the caller's responsibility to ensure
690  pattern, and the same tables are used via this pointer by \fBpcre_study()\fR  that the memory containing the tables remains available for as long as it is
691  and \fBpcre_exec()\fR. Thus, for any single pattern, compilation, studying and  needed.
692  matching all happen in the same locale, but different patterns can be compiled  .P
693  in different locales. It is the caller's responsibility to ensure that the  The pointer that is passed to \fBpcre_compile()\fP is saved with the compiled
694  memory containing the tables remains available for as long as it is needed.  pattern, and the same tables are used via this pointer by \fBpcre_study()\fP
695    and normally also by \fBpcre_exec()\fP. Thus, by default, for any single
696  .SH INFORMATION ABOUT A PATTERN  pattern, compilation, studying and matching all happen in the same locale, but
697    different patterns can be compiled in different locales.
698    .P
699    It is possible to pass a table pointer or NULL (indicating the use of the
700    internal tables) to \fBpcre_exec()\fP. Although not intended for this purpose,
701    this facility could be used to match a pattern in a different locale from the
702    one in which it was compiled. Passing table pointers at run time is discussed
703    below in the section on matching a pattern.
704    .
705    .
706    .SH "INFORMATION ABOUT A PATTERN"
707  .rs  .rs
708  .sp  .sp
709  .B int pcre_fullinfo(const pcre *\fIcode\fR, "const pcre_extra *\fIextra\fR,"  .B int pcre_fullinfo(const pcre *\fIcode\fP, "const pcre_extra *\fIextra\fP,"
710  .ti +5n  .ti +5n
711  .B int \fIwhat\fR, void *\fIwhere\fR);  .B int \fIwhat\fP, void *\fIwhere\fP);
712  .PP  .PP
713  The \fBpcre_fullinfo()\fR function returns information about a compiled  The \fBpcre_fullinfo()\fP function returns information about a compiled
714  pattern. It replaces the obsolete \fBpcre_info()\fR function, which is  pattern. It replaces the obsolete \fBpcre_info()\fP function, which is
715  nevertheless retained for backwards compability (and is documented below).  nevertheless retained for backwards compability (and is documented below).
716    .P
717  The first argument for \fBpcre_fullinfo()\fR is a pointer to the compiled  The first argument for \fBpcre_fullinfo()\fP is a pointer to the compiled
718  pattern. The second argument is the result of \fBpcre_study()\fR, or NULL if  pattern. The second argument is the result of \fBpcre_study()\fP, or NULL if
719  the pattern was not studied. The third argument specifies which piece of  the pattern was not studied. The third argument specifies which piece of
720  information is required, and the fourth argument is a pointer to a variable  information is required, and the fourth argument is a pointer to a variable
721  to receive the data. The yield of the function is zero for success, or one of  to receive the data. The yield of the function is zero for success, or one of
722  the following negative numbers:  the following negative numbers:
723    .sp
724    PCRE_ERROR_NULL       the argument \fIcode\fR was NULL    PCRE_ERROR_NULL       the argument \fIcode\fP was NULL
725                          the argument \fIwhere\fR was NULL                          the argument \fIwhere\fP was NULL
726    PCRE_ERROR_BADMAGIC   the "magic number" was not found    PCRE_ERROR_BADMAGIC   the "magic number" was not found
727    PCRE_ERROR_BADOPTION  the value of \fIwhat\fR was invalid    PCRE_ERROR_BADOPTION  the value of \fIwhat\fP was invalid
728    .sp
729  Here is a typical call of \fBpcre_fullinfo()\fR, to obtain the length of the  The "magic number" is placed at the start of each compiled pattern as an simple
730  compiled pattern:  check against passing an arbitrary memory pointer. Here is a typical call of
731    \fBpcre_fullinfo()\fP, to obtain the length of the compiled pattern:
732    .sp
733    int rc;    int rc;
734    unsigned long int length;    unsigned long int length;
735    rc = pcre_fullinfo(    rc = pcre_fullinfo(
# Line 489  compiled pattern: Line 737  compiled pattern:
737      pe,               /* result of pcre_study(), or NULL */      pe,               /* result of pcre_study(), or NULL */
738      PCRE_INFO_SIZE,   /* what is required */      PCRE_INFO_SIZE,   /* what is required */
739      &length);         /* where to put the data */      &length);         /* where to put the data */
740    .sp
741  The possible values for the third argument are defined in \fBpcre.h\fR, and are  The possible values for the third argument are defined in \fBpcre.h\fP, and are
742  as follows:  as follows:
743    .sp
744    PCRE_INFO_BACKREFMAX    PCRE_INFO_BACKREFMAX
745    .sp
746  Return the number of the highest back reference in the pattern. The fourth  Return the number of the highest back reference in the pattern. The fourth
747  argument should point to an \fBint\fR variable. Zero is returned if there are  argument should point to an \fBint\fP variable. Zero is returned if there are
748  no back references.  no back references.
749    .sp
750    PCRE_INFO_CAPTURECOUNT    PCRE_INFO_CAPTURECOUNT
751    .sp
752  Return the number of capturing subpatterns in the pattern. The fourth argument  Return the number of capturing subpatterns in the pattern. The fourth argument
753  should point to an \fbint\fR variable.  should point to an \fBint\fP variable.
754    .sp
755      PCRE_INFO_DEFAULT_TABLES
756    .sp
757    Return a pointer to the internal default character tables within PCRE. The
758    fourth argument should point to an \fBunsigned char *\fP variable. This
759    information call is provided for internal use by the \fBpcre_study()\fP
760    function. External callers can cause PCRE to use its internal tables by passing
761    a NULL table pointer.
762    .sp
763    PCRE_INFO_FIRSTBYTE    PCRE_INFO_FIRSTBYTE
764    .sp
765  Return information about the first byte of any matched string, for a  Return information about the first byte of any matched string, for a
766  non-anchored pattern. (This option used to be called PCRE_INFO_FIRSTCHAR; the  non-anchored pattern. (This option used to be called PCRE_INFO_FIRSTCHAR; the
767  old name is still recognized for backwards compatibility.)  old name is still recognized for backwards compatibility.)
768    .P
769  If there is a fixed first byte, e.g. from a pattern such as (cat|cow|coyote),  If there is a fixed first byte, for example, from a pattern such as
770  it is returned in the integer pointed to by \fIwhere\fR. Otherwise, if either  (cat|cow|coyote), it is returned in the integer pointed to by \fIwhere\fP.
771    Otherwise, if either
772    .sp
773  (a) the pattern was compiled with the PCRE_MULTILINE option, and every branch  (a) the pattern was compiled with the PCRE_MULTILINE option, and every branch
774  starts with "^", or  starts with "^", or
775    .sp
776  (b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not set  (b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not set
777  (if it were set, the pattern would be anchored),  (if it were set, the pattern would be anchored),
778    .sp
779  -1 is returned, indicating that the pattern matches only at the start of a  -1 is returned, indicating that the pattern matches only at the start of a
780  subject string or after any newline within the string. Otherwise -2 is  subject string or after any newline within the string. Otherwise -2 is
781  returned. For anchored patterns, -2 is returned.  returned. For anchored patterns, -2 is returned.
782    .sp
783    PCRE_INFO_FIRSTTABLE    PCRE_INFO_FIRSTTABLE
784    .sp
785  If the pattern was studied, and this resulted in the construction of a 256-bit  If the pattern was studied, and this resulted in the construction of a 256-bit
786  table indicating a fixed set of bytes for the first byte in any matching  table indicating a fixed set of bytes for the first byte in any matching
787  string, a pointer to the table is returned. Otherwise NULL is returned. The  string, a pointer to the table is returned. Otherwise NULL is returned. The
788  fourth argument should point to an \fBunsigned char *\fR variable.  fourth argument should point to an \fBunsigned char *\fP variable.
789    .sp
790    PCRE_INFO_LASTLITERAL    PCRE_INFO_LASTLITERAL
791    .sp
792  Return the value of the rightmost literal byte that must exist in any matched  Return the value of the rightmost literal byte that must exist in any matched
793  string, other than at its start, if such a byte has been recorded. The fourth  string, other than at its start, if such a byte has been recorded. The fourth
794  argument should point to an \fBint\fR variable. If there is no such byte, -1 is  argument should point to an \fBint\fP variable. If there is no such byte, -1 is
795  returned. For anchored patterns, a last literal byte is recorded only if it  returned. For anchored patterns, a last literal byte is recorded only if it
796  follows something of variable length. For example, for the pattern  follows something of variable length. For example, for the pattern
797  /^a\\d+z\\d+/ the returned value is "z", but for /^a\\dz\\d/ the returned value  /^a\ed+z\ed+/ the returned value is "z", but for /^a\edz\ed/ the returned value
798  is -1.  is -1.
799    .sp
800    PCRE_INFO_NAMECOUNT    PCRE_INFO_NAMECOUNT
801    PCRE_INFO_NAMEENTRYSIZE    PCRE_INFO_NAMEENTRYSIZE
802    PCRE_INFO_NAMETABLE    PCRE_INFO_NAMETABLE
803    .sp
804  PCRE supports the use of named as well as numbered capturing parentheses. The  PCRE supports the use of named as well as numbered capturing parentheses. The
805  names are just an additional way of identifying the parentheses, which still  names are just an additional way of identifying the parentheses, which still
806  acquire a number. A caller that wants to extract data from a named subpattern  acquire numbers. A convenience function called \fBpcre_get_named_substring()\fP
807  must convert the name to a number in order to access the correct pointers in  is provided for extracting an individual captured substring by name. It is also
808  the output vector (described with \fBpcre_exec()\fR below). In order to do  possible to extract the data directly, by first converting the name to a number
809  this, it must first use these three values to obtain the name-to-number mapping  in order to access the correct pointers in the output vector (described with
810  table for the pattern.  \fBpcre_exec()\fP below). To do the conversion, you need to use the
811    name-to-number map, which is described by these three values.
812    .P
813  The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT gives  The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT gives
814  the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size of each  the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size of each
815  entry; both of these return an \fBint\fR value. The entry size depends on the  entry; both of these return an \fBint\fP value. The entry size depends on the
816  length of the longest name. PCRE_INFO_NAMETABLE returns a pointer to the first  length of the longest name. PCRE_INFO_NAMETABLE returns a pointer to the first
817  entry of the table (a pointer to \fBchar\fR). The first two bytes of each entry  entry of the table (a pointer to \fBchar\fP). The first two bytes of each entry
818  are the number of the capturing parenthesis, most significant byte first. The  are the number of the capturing parenthesis, most significant byte first. The
819  rest of the entry is the corresponding name, zero terminated. The names are in  rest of the entry is the corresponding name, zero terminated. The names are in
820  alphabetical order. For example, consider the following pattern (assume  alphabetical order. For example, consider the following pattern (assume
821  PCRE_EXTENDED is set, so white space - including newlines - is ignored):  PCRE_EXTENDED is set, so white space - including newlines - is ignored):
822    .sp
823    (?P<date> (?P<year>(\\d\\d)?\\d\\d) -  .\" JOIN
824    (?P<month>\\d\\d) - (?P<day>\\d\\d) )    (?P<date> (?P<year>(\ed\ed)?\ed\ed) -
825      (?P<month>\ed\ed) - (?P<day>\ed\ed) )
826    .sp
827  There are four named subpatterns, so the table has four entries, and each entry  There are four named subpatterns, so the table has four entries, and each entry
828  in the table is eight bytes long. The table is as follows, with non-printing  in the table is eight bytes long. The table is as follows, with non-printing
829  bytes shows in hex, and undefined bytes shown as ??:  bytes shows in hexadecimal, and undefined bytes shown as ??:
830    .sp
831    00 01 d  a  t  e  00 ??    00 01 d  a  t  e  00 ??
832    00 05 d  a  y  00 ?? ??    00 05 d  a  y  00 ?? ??
833    00 04 m  o  n  t  h  00    00 04 m  o  n  t  h  00
834    00 02 y  e  a  r  00 ??    00 02 y  e  a  r  00 ??
835    .sp
836  When writing code to extract data from named subpatterns, remember that the  When writing code to extract data from named subpatterns using the
837  length of each entry may be different for each compiled pattern.  name-to-number map, remember that the length of each entry is likely to be
838    different for each compiled pattern.
839    .sp
840    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
841    .sp
842  Return a copy of the options with which the pattern was compiled. The fourth  Return a copy of the options with which the pattern was compiled. The fourth
843  argument should point to an \fBunsigned long int\fR variable. These option bits  argument should point to an \fBunsigned long int\fP variable. These option bits
844  are those specified in the call to \fBpcre_compile()\fR, modified by any  are those specified in the call to \fBpcre_compile()\fP, modified by any
845  top-level option settings within the pattern itself.  top-level option settings within the pattern itself.
846    .P
847  A pattern is automatically anchored by PCRE if all of its top-level  A pattern is automatically anchored by PCRE if all of its top-level
848  alternatives begin with one of the following:  alternatives begin with one of the following:
849    .sp
850    ^     unless PCRE_MULTILINE is set    ^     unless PCRE_MULTILINE is set
851    \\A    always    \eA    always
852    \\G    always    \eG    always
853    .\" JOIN
854    .*    if PCRE_DOTALL is set and there are no back    .*    if PCRE_DOTALL is set and there are no back
855            references to the subpattern in which .* appears            references to the subpattern in which .* appears
856    .sp
857  For such patterns, the PCRE_ANCHORED bit is set in the options returned by  For such patterns, the PCRE_ANCHORED bit is set in the options returned by
858  \fBpcre_fullinfo()\fR.  \fBpcre_fullinfo()\fP.
859    .sp
860    PCRE_INFO_SIZE    PCRE_INFO_SIZE
861    .sp
862  Return the size of the compiled pattern, that is, the value that was passed as  Return the size of the compiled pattern, that is, the value that was passed as
863  the argument to \fBpcre_malloc()\fR when PCRE was getting memory in which to  the argument to \fBpcre_malloc()\fP when PCRE was getting memory in which to
864  place the compiled data. The fourth argument should point to a \fBsize_t\fR  place the compiled data. The fourth argument should point to a \fBsize_t\fP
865  variable.  variable.
866    .sp
867    PCRE_INFO_STUDYSIZE    PCRE_INFO_STUDYSIZE
868    .sp
869  Returns the size of the data block pointed to by the \fIstudy_data\fR field in  Return the size of the data block pointed to by the \fIstudy_data\fP field in
870  a \fBpcre_extra\fR block. That is, it is the value that was passed to  a \fBpcre_extra\fP block. That is, it is the value that was passed to
871  \fBpcre_malloc()\fR when PCRE was getting memory into which to place the data  \fBpcre_malloc()\fP when PCRE was getting memory into which to place the data
872  created by \fBpcre_study()\fR. The fourth argument should point to a  created by \fBpcre_study()\fP. The fourth argument should point to a
873  \fBsize_t\fR variable.  \fBsize_t\fP variable.
874    .
875  .SH OBSOLETE INFO FUNCTION  .
876    .SH "OBSOLETE INFO FUNCTION"
877  .rs  .rs
878  .sp  .sp
879  .B int pcre_info(const pcre *\fIcode\fR, int *\fIoptptr\fR, int  .B int pcre_info(const pcre *\fIcode\fP, int *\fIoptptr\fP, int
880  .B *\fIfirstcharptr\fR);  .B *\fIfirstcharptr\fP);
881  .PP  .PP
882  The \fBpcre_info()\fR function is now obsolete because its interface is too  The \fBpcre_info()\fP function is now obsolete because its interface is too
883  restrictive to return all the available data about a compiled pattern. New  restrictive to return all the available data about a compiled pattern. New
884  programs should use \fBpcre_fullinfo()\fR instead. The yield of  programs should use \fBpcre_fullinfo()\fP instead. The yield of
885  \fBpcre_info()\fR is the number of capturing subpatterns, or one of the  \fBpcre_info()\fP is the number of capturing subpatterns, or one of the
886  following negative numbers:  following negative numbers:
887    .sp
888    PCRE_ERROR_NULL       the argument \fIcode\fR was NULL    PCRE_ERROR_NULL       the argument \fIcode\fP was NULL
889    PCRE_ERROR_BADMAGIC   the "magic number" was not found    PCRE_ERROR_BADMAGIC   the "magic number" was not found
890    .sp
891  If the \fIoptptr\fR argument is not NULL, a copy of the options with which the  If the \fIoptptr\fP argument is not NULL, a copy of the options with which the
892  pattern was compiled is placed in the integer it points to (see  pattern was compiled is placed in the integer it points to (see
893  PCRE_INFO_OPTIONS above).  PCRE_INFO_OPTIONS above).
894    .P
895  If the pattern is not anchored and the \fIfirstcharptr\fR argument is not NULL,  If the pattern is not anchored and the \fIfirstcharptr\fP argument is not NULL,
896  it is used to pass back information about the first character of any matched  it is used to pass back information about the first character of any matched
897  string (see PCRE_INFO_FIRSTBYTE above).  string (see PCRE_INFO_FIRSTBYTE above).
898    .
899  .SH MATCHING A PATTERN  .
900    .SH "REFERENCE COUNTS"
901  .rs  .rs
902  .sp  .sp
903  .B int pcre_exec(const pcre *\fIcode\fR, "const pcre_extra *\fIextra\fR,"  .B int pcre_refcount(pcre *\fIcode\fP, int \fIadjust\fP);
904    .PP
905    The \fBpcre_refcount()\fP function is used to maintain a reference count in the
906    data block that contains a compiled pattern. It is provided for the benefit of
907    applications that operate in an object-oriented manner, where different parts
908    of the application may be using the same compiled pattern, but you want to free
909    the block when they are all done.
910    .P
911    When a pattern is compiled, the reference count field is initialized to zero.
912    It is changed only by calling this function, whose action is to add the
913    \fIadjust\fP value (which may be positive or negative) to it. The yield of the
914    function is the new value. However, the value of the count is constrained to
915    lie between 0 and 65535, inclusive. If the new value is outside these limits,
916    it is forced to the appropriate limit value.
917    .P
918    Except when it is zero, the reference count is not correctly preserved if a
919    pattern is compiled on one host and then transferred to a host whose byte-order
920    is different. (This seems a highly unlikely scenario.)
921    .
922    .
923    .SH "MATCHING A PATTERN: THE TRADITIONAL FUNCTION"
924    .rs
925    .sp
926    .B int pcre_exec(const pcre *\fIcode\fP, "const pcre_extra *\fIextra\fP,"
927  .ti +5n  .ti +5n
928  .B "const char *\fIsubject\fR," int \fIlength\fR, int \fIstartoffset\fR,  .B "const char *\fIsubject\fP," int \fIlength\fP, int \fIstartoffset\fP,
929  .ti +5n  .ti +5n
930  .B int \fIoptions\fR, int *\fIovector\fR, int \fIovecsize\fR);  .B int \fIoptions\fP, int *\fIovector\fP, int \fIovecsize\fP);
931  .PP  .P
932  The function \fBpcre_exec()\fR is called to match a subject string against a  The function \fBpcre_exec()\fP is called to match a subject string against a
933  pre-compiled pattern, which is passed in the \fIcode\fR argument. If the  compiled pattern, which is passed in the \fIcode\fP argument. If the
934  pattern has been studied, the result of the study should be passed in the  pattern has been studied, the result of the study should be passed in the
935  \fIextra\fR argument.  \fIextra\fP argument. This function is the main matching facility of the
936    library, and it operates in a Perl-like manner. For specialist use there is
937  Here is an example of a simple call to \fBpcre_exec()\fR:  also an alternative matching function, which is described
938    .\" HTML <a href="#dfamatch">
939    .\" </a>
940    below
941    .\"
942    in the section about the \fBpcre_dfa_exec()\fP function.
943    .P
944    In most applications, the pattern will have been compiled (and optionally
945    studied) in the same process that calls \fBpcre_exec()\fP. However, it is
946    possible to save compiled patterns and study data, and then use them later
947    in different processes, possibly even on different hosts. For a discussion
948    about this, see the
949    .\" HREF
950    \fBpcreprecompile\fP
951    .\"
952    documentation.
953    .P
954    Here is an example of a simple call to \fBpcre_exec()\fP:
955    .sp
956    int rc;    int rc;
957    int ovector[30];    int ovector[30];
958    rc = pcre_exec(    rc = pcre_exec(
# Line 659  Here is an example of a simple call to \ Line 962  Here is an example of a simple call to \
962      11,             /* the length of the subject string */      11,             /* the length of the subject string */
963      0,              /* start at offset 0 in the subject */      0,              /* start at offset 0 in the subject */
964      0,              /* default options */      0,              /* default options */
965      ovector,        /* vector for substring information */      ovector,        /* vector of integers for substring information */
966      30);            /* number of elements in the vector */      30);            /* number of elements (NOT size in bytes) */
967    .
968  If the \fIextra\fR argument is not NULL, it must point to a \fBpcre_extra\fR  .\" HTML <a name="extradata"></a>
969  data block. The \fBpcre_study()\fR function returns such a block (when it  .SS "Extra data for \fBpcre_exec()\fR"
970    .rs
971    .sp
972    If the \fIextra\fP argument is not NULL, it must point to a \fBpcre_extra\fP
973    data block. The \fBpcre_study()\fP function returns such a block (when it
974  doesn't return NULL), but you can also create one for yourself, and pass  doesn't return NULL), but you can also create one for yourself, and pass
975  additional information in it. The fields in the block are as follows:  additional information in it. The \fBpcre_extra\fP block contains the following
976    fields (not necessarily in this order):
977    unsigned long int \fIflags\fR;  .sp
978    void *\fIstudy_data\fR;    unsigned long int \fIflags\fP;
979    unsigned long int \fImatch_limit\fR;    void *\fIstudy_data\fP;
980    void *\fIcallout_data\fR;    unsigned long int \fImatch_limit\fP;
981      unsigned long int \fImatch_limit_recursion\fP;
982  The \fIflags\fR field is a bitmap that specifies which of the other fields    void *\fIcallout_data\fP;
983      const unsigned char *\fItables\fP;
984    .sp
985    The \fIflags\fP field is a bitmap that specifies which of the other fields
986  are set. The flag bits are:  are set. The flag bits are:
987    .sp
988    PCRE_EXTRA_STUDY_DATA    PCRE_EXTRA_STUDY_DATA
989    PCRE_EXTRA_MATCH_LIMIT    PCRE_EXTRA_MATCH_LIMIT
990      PCRE_EXTRA_MATCH_LIMIT_RECURSION
991    PCRE_EXTRA_CALLOUT_DATA    PCRE_EXTRA_CALLOUT_DATA
992      PCRE_EXTRA_TABLES
993  Other flag bits should be set to zero. The \fIstudy_data\fR field is set in the  .sp
994  \fBpcre_extra\fR block that is returned by \fBpcre_study()\fR, together with  Other flag bits should be set to zero. The \fIstudy_data\fP field is set in the
995  the appropriate flag bit. You should not set this yourself, but you can add to  \fBpcre_extra\fP block that is returned by \fBpcre_study()\fP, together with
996  the block by setting the other fields.  the appropriate flag bit. You should not set this yourself, but you may add to
997    the block by setting the other fields and their corresponding flag bits.
998  The \fImatch_limit\fR field provides a means of preventing PCRE from using up a  .P
999    The \fImatch_limit\fP field provides a means of preventing PCRE from using up a
1000  vast amount of resources when running patterns that are not going to match,  vast amount of resources when running patterns that are not going to match,
1001  but which have a very large number of possibilities in their search trees. The  but which have a very large number of possibilities in their search trees. The
1002  classic example is the use of nested unlimited repeats. Internally, PCRE uses a  classic example is the use of nested unlimited repeats.
1003  function called \fBmatch()\fR which it calls repeatedly (sometimes  .P
1004  recursively). The limit is imposed on the number of times this function is  Internally, PCRE uses a function called \fBmatch()\fP which it calls repeatedly
1005  called during a match, which has the effect of limiting the amount of recursion  (sometimes recursively). The limit set by \fImatch_limit\fP is imposed on the
1006  and backtracking that can take place. For patterns that are not anchored, the  number of times this function is called during a match, which has the effect of
1007  count starts from zero for each position in the subject string.  limiting the amount of backtracking that can take place. For patterns that are
1008    not anchored, the count restarts from zero for each position in the subject
1009  The default limit for the library can be set when PCRE is built; the default  string.
1010    .P
1011    The default value for the limit can be set when PCRE is built; the default
1012  default is 10 million, which handles all but the most extreme cases. You can  default is 10 million, which handles all but the most extreme cases. You can
1013  reduce the default by suppling \fBpcre_exec()\fR with a \fRpcre_extra\fR block  override the default by suppling \fBpcre_exec()\fP with a \fBpcre_extra\fP
1014  in which \fImatch_limit\fR is set to a smaller value, and  block in which \fImatch_limit\fP is set, and PCRE_EXTRA_MATCH_LIMIT is set in
1015  PCRE_EXTRA_MATCH_LIMIT is set in the \fIflags\fR field. If the limit is  the \fIflags\fP field. If the limit is exceeded, \fBpcre_exec()\fP returns
1016  exceeded, \fBpcre_exec()\fR returns PCRE_ERROR_MATCHLIMIT.  PCRE_ERROR_MATCHLIMIT.
1017    .P
1018  The \fIpcre_callout\fR field is used in conjunction with the "callout" feature,  The \fImatch_limit_recursion\fP field is similar to \fImatch_limit\fP, but
1019  which is described in the \fBpcrecallout\fR documentation.  instead of limiting the total number of times that \fBmatch()\fP is called, it
1020    limits the depth of recursion. The recursion depth is a smaller number than the
1021  The PCRE_ANCHORED option can be passed in the \fIoptions\fR argument, whose  total number of calls, because not all calls to \fBmatch()\fP are recursive.
1022  unused bits must be zero. This limits \fBpcre_exec()\fR to matching at the  This limit is of use only if it is set smaller than \fImatch_limit\fP.
1023  first matching position. However, if a pattern was compiled with PCRE_ANCHORED,  .P
1024  or turned out to be anchored by virtue of its contents, it cannot be made  Limiting the recursion depth limits the amount of stack that can be used, or,
1025  unachored at matching time.  when PCRE has been compiled to use memory on the heap instead of the stack, the
1026    amount of heap memory that can be used.
1027  When PCRE_UTF8 was set at compile time, the validity of the subject as a UTF-8  .P
1028  string is automatically checked. If an invalid UTF-8 sequence of bytes is  The default value for \fImatch_limit_recursion\fP can be set when PCRE is
1029  found, \fBpcre_exec()\fR returns the error PCRE_ERROR_BADUTF8. If you already  built; the default default is the same value as the default for
1030  know that your subject is valid, and you want to skip this check for  \fImatch_limit\fP. You can override the default by suppling \fBpcre_exec()\fP
1031  performance reasons, you can set the PCRE_NO_UTF8_CHECK option when calling  with a \fBpcre_extra\fP block in which \fImatch_limit_recursion\fP is set, and
1032  \fBpcre_exec()\fR. When this option is set, the effect of passing an invalid  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set in the \fIflags\fP field. If the limit
1033  UTF-8 string as a subject is undefined. It may cause your program to crash.  is exceeded, \fBpcre_exec()\fP returns PCRE_ERROR_RECURSIONLIMIT.
1034    .P
1035  There are also three further options that can be set only at matching time:  The \fIpcre_callout\fP field is used in conjunction with the "callout" feature,
1036    which is described in the
1037    .\" HREF
1038    \fBpcrecallout\fP
1039    .\"
1040    documentation.
1041    .P
1042    The \fItables\fP field is used to pass a character tables pointer to
1043    \fBpcre_exec()\fP; this overrides the value that is stored with the compiled
1044    pattern. A non-NULL value is stored with the compiled pattern only if custom
1045    tables were supplied to \fBpcre_compile()\fP via its \fItableptr\fP argument.
1046    If NULL is passed to \fBpcre_exec()\fP using this mechanism, it forces PCRE's
1047    internal tables to be used. This facility is helpful when re-using patterns
1048    that have been saved after compiling with an external set of tables, because
1049    the external tables might be at a different address when \fBpcre_exec()\fP is
1050    called. See the
1051    .\" HREF
1052    \fBpcreprecompile\fP
1053    .\"
1054    documentation for a discussion of saving compiled patterns for later use.
1055    .
1056    .SS "Option bits for \fBpcre_exec()\fP"
1057    .rs
1058    .sp
1059    The unused bits of the \fIoptions\fP argument for \fBpcre_exec()\fP must be
1060    zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NOTBOL,
1061    PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL.
1062    .sp
1063      PCRE_ANCHORED
1064    .sp
1065    The PCRE_ANCHORED option limits \fBpcre_exec()\fP to matching at the first
1066    matching position. If a pattern was compiled with PCRE_ANCHORED, or turned out
1067    to be anchored by virtue of its contents, it cannot be made unachored at
1068    matching time.
1069    .sp
1070    PCRE_NOTBOL    PCRE_NOTBOL
1071    .sp
1072  The first character of the string is not the beginning of a line, so the  This option specifies that first character of the subject string is not the
1073  circumflex metacharacter should not match before it. Setting this without  beginning of a line, so the circumflex metacharacter should not match before
1074  PCRE_MULTILINE (at compile time) causes circumflex never to match.  it. Setting this without PCRE_MULTILINE (at compile time) causes circumflex
1075    never to match. This option affects only the behaviour of the circumflex
1076    metacharacter. It does not affect \eA.
1077    .sp
1078    PCRE_NOTEOL    PCRE_NOTEOL
1079    .sp
1080  The end of the string is not the end of a line, so the dollar metacharacter  This option specifies that the end of the subject string is not the end of a
1081  should not match it nor (except in multiline mode) a newline immediately before  line, so the dollar metacharacter should not match it nor (except in multiline
1082  it. Setting this without PCRE_MULTILINE (at compile time) causes dollar never  mode) a newline immediately before it. Setting this without PCRE_MULTILINE (at
1083  to match.  compile time) causes dollar never to match. This option affects only the
1084    behaviour of the dollar metacharacter. It does not affect \eZ or \ez.
1085    .sp
1086    PCRE_NOTEMPTY    PCRE_NOTEMPTY
1087    .sp
1088  An empty string is not considered to be a valid match if this option is set. If  An empty string is not considered to be a valid match if this option is set. If
1089  there are alternatives in the pattern, they are tried. If all the alternatives  there are alternatives in the pattern, they are tried. If all the alternatives
1090  match the empty string, the entire match fails. For example, if the pattern  match the empty string, the entire match fails. For example, if the pattern
1091    .sp
1092    a?b?    a?b?
1093    .sp
1094  is applied to a string not beginning with "a" or "b", it matches the empty  is applied to a string not beginning with "a" or "b", it matches the empty
1095  string at the start of the subject. With PCRE_NOTEMPTY set, this match is not  string at the start of the subject. With PCRE_NOTEMPTY set, this match is not
1096  valid, so PCRE searches further into the string for occurrences of "a" or "b".  valid, so PCRE searches further into the string for occurrences of "a" or "b".
1097    .P
1098  Perl has no direct equivalent of PCRE_NOTEMPTY, but it does make a special case  Perl has no direct equivalent of PCRE_NOTEMPTY, but it does make a special case
1099  of a pattern match of the empty string within its \fBsplit()\fR function, and  of a pattern match of the empty string within its \fBsplit()\fP function, and
1100  when using the /g modifier. It is possible to emulate Perl's behaviour after  when using the /g modifier. It is possible to emulate Perl's behaviour after
1101  matching a null string by first trying the match again at the same offset with  matching a null string by first trying the match again at the same offset with
1102  PCRE_NOTEMPTY set, and then if that fails by advancing the starting offset (see  PCRE_NOTEMPTY and PCRE_ANCHORED, and then if that fails by advancing the
1103  below) and trying an ordinary match again.  starting offset (see below) and trying an ordinary match again. There is some
1104    code that demonstrates how to do this in the \fIpcredemo.c\fP sample program.
1105  The subject string is passed to \fBpcre_exec()\fR as a pointer in  .sp
1106  \fIsubject\fR, a length in \fIlength\fR, and a starting offset in    PCRE_NO_UTF8_CHECK
1107  \fIstartoffset\fR. Unlike the pattern string, the subject may contain binary  .sp
1108  zero bytes. When the starting offset is zero, the search for a match starts at  When PCRE_UTF8 is set at compile time, the validity of the subject as a UTF-8
1109  the beginning of the subject, and this is by far the most common case.  string is automatically checked when \fBpcre_exec()\fP is subsequently called.
1110    The value of \fIstartoffset\fP is also checked to ensure that it points to the
1111  If the pattern was compiled with the PCRE_UTF8 option, the subject must be a  start of a UTF-8 character. If an invalid UTF-8 sequence of bytes is found,
1112  sequence of bytes that is a valid UTF-8 string. If an invalid UTF-8 string is  \fBpcre_exec()\fP returns the error PCRE_ERROR_BADUTF8. If \fIstartoffset\fP
1113  passed, PCRE's behaviour is not defined.  contains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.
1114    .P
1115    If you already know that your subject is valid, and you want to skip these
1116    checks for performance reasons, you can set the PCRE_NO_UTF8_CHECK option when
1117    calling \fBpcre_exec()\fP. You might want to do this for the second and
1118    subsequent calls to \fBpcre_exec()\fP if you are making repeated calls to find
1119    all the matches in a single subject string. However, you should be sure that
1120    the value of \fIstartoffset\fP points to the start of a UTF-8 character. When
1121    PCRE_NO_UTF8_CHECK is set, the effect of passing an invalid UTF-8 string as a
1122    subject, or a value of \fIstartoffset\fP that does not point to the start of a
1123    UTF-8 character, is undefined. Your program may crash.
1124    .sp
1125      PCRE_PARTIAL
1126    .sp
1127    This option turns on the partial matching feature. If the subject string fails
1128    to match the pattern, but at some point during the matching process the end of
1129    the subject was reached (that is, the subject partially matches the pattern and
1130    the failure to match occurred only because there were not enough subject
1131    characters), \fBpcre_exec()\fP returns PCRE_ERROR_PARTIAL instead of
1132    PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is used, there are restrictions on what
1133    may appear in the pattern. These are discussed in the
1134    .\" HREF
1135    \fBpcrepartial\fP
1136    .\"
1137    documentation.
1138    .
1139    .SS "The string to be matched by \fBpcre_exec()\fP"
1140    .rs
1141    .sp
1142    The subject string is passed to \fBpcre_exec()\fP as a pointer in
1143    \fIsubject\fP, a length in \fIlength\fP, and a starting byte offset in
1144    \fIstartoffset\fP. In UTF-8 mode, the byte offset must point to the start of a
1145    UTF-8 character. Unlike the pattern string, the subject may contain binary zero
1146    bytes. When the starting offset is zero, the search for a match starts at the
1147    beginning of the subject, and this is by far the most common case.
1148    .P
1149  A non-zero starting offset is useful when searching for another match in the  A non-zero starting offset is useful when searching for another match in the
1150  same subject by calling \fBpcre_exec()\fR again after a previous success.  same subject by calling \fBpcre_exec()\fP again after a previous success.
1151  Setting \fIstartoffset\fR differs from just passing over a shortened string and  Setting \fIstartoffset\fP differs from just passing over a shortened string and
1152  setting PCRE_NOTBOL in the case of a pattern that begins with any kind of  setting PCRE_NOTBOL in the case of a pattern that begins with any kind of
1153  lookbehind. For example, consider the pattern  lookbehind. For example, consider the pattern
1154    .sp
1155    \\Biss\\B    \eBiss\eB
1156    .sp
1157  which finds occurrences of "iss" in the middle of words. (\\B matches only if  which finds occurrences of "iss" in the middle of words. (\eB matches only if
1158  the current position in the subject is not a word boundary.) When applied to  the current position in the subject is not a word boundary.) When applied to
1159  the string "Mississipi" the first call to \fBpcre_exec()\fR finds the first  the string "Mississipi" the first call to \fBpcre_exec()\fP finds the first
1160  occurrence. If \fBpcre_exec()\fR is called again with just the remainder of the  occurrence. If \fBpcre_exec()\fP is called again with just the remainder of the
1161  subject, namely "issipi", it does not match, because \\B is always false at the  subject, namely "issipi", it does not match, because \eB is always false at the
1162  start of the subject, which is deemed to be a word boundary. However, if  start of the subject, which is deemed to be a word boundary. However, if
1163  \fBpcre_exec()\fR is passed the entire string again, but with \fIstartoffset\fR  \fBpcre_exec()\fP is passed the entire string again, but with \fIstartoffset\fP
1164  set to 4, it finds the second occurrence of "iss" because it is able to look  set to 4, it finds the second occurrence of "iss" because it is able to look
1165  behind the starting point to discover that it is preceded by a letter.  behind the starting point to discover that it is preceded by a letter.
1166    .P
1167  If a non-zero starting offset is passed when the pattern is anchored, one  If a non-zero starting offset is passed when the pattern is anchored, one
1168  attempt to match at the given offset is tried. This can only succeed if the  attempt to match at the given offset is made. This can only succeed if the
1169  pattern does not require the match to be at the start of the subject.  pattern does not require the match to be at the start of the subject.
1170    .
1171    .SS "How \fBpcre_exec()\fP returns captured substrings"
1172    .rs
1173    .sp
1174  In general, a pattern matches a certain portion of the subject, and in  In general, a pattern matches a certain portion of the subject, and in
1175  addition, further substrings from the subject may be picked out by parts of the  addition, further substrings from the subject may be picked out by parts of the
1176  pattern. Following the usage in Jeffrey Friedl's book, this is called  pattern. Following the usage in Jeffrey Friedl's book, this is called
1177  "capturing" in what follows, and the phrase "capturing subpattern" is used for  "capturing" in what follows, and the phrase "capturing subpattern" is used for
1178  a fragment of a pattern that picks out a substring. PCRE supports several other  a fragment of a pattern that picks out a substring. PCRE supports several other
1179  kinds of parenthesized subpattern that do not cause substrings to be captured.  kinds of parenthesized subpattern that do not cause substrings to be captured.
1180    .P
1181  Captured substrings are returned to the caller via a vector of integer offsets  Captured substrings are returned to the caller via a vector of integer offsets
1182  whose address is passed in \fIovector\fR. The number of elements in the vector  whose address is passed in \fIovector\fP. The number of elements in the vector
1183  is passed in \fIovecsize\fR. The first two-thirds of the vector is used to pass  is passed in \fIovecsize\fP, which must be a non-negative number. \fBNote\fP:
1184  back captured substrings, each substring using a pair of integers. The  this argument is NOT the size of \fIovector\fP in bytes.
1185  remaining third of the vector is used as workspace by \fBpcre_exec()\fR while  .P
1186  matching capturing subpatterns, and is not available for passing back  The first two-thirds of the vector is used to pass back captured substrings,
1187  information. The length passed in \fIovecsize\fR should always be a multiple of  each substring using a pair of integers. The remaining third of the vector is
1188  three. If it is not, it is rounded down.  used as workspace by \fBpcre_exec()\fP while matching capturing subpatterns,
1189    and is not available for passing back information. The length passed in
1190  When a match has been successful, information about captured substrings is  \fIovecsize\fP should always be a multiple of three. If it is not, it is
1191  returned in pairs of integers, starting at the beginning of \fIovector\fR, and  rounded down.
1192    .P
1193    When a match is successful, information about captured substrings is returned
1194    in pairs of integers, starting at the beginning of \fIovector\fP, and
1195  continuing up to two-thirds of its length at the most. The first element of a  continuing up to two-thirds of its length at the most. The first element of a
1196  pair is set to the offset of the first character in a substring, and the second  pair is set to the offset of the first character in a substring, and the second
1197  is set to the offset of the first character after the end of a substring. The  is set to the offset of the first character after the end of a substring. The
1198  first pair, \fIovector[0]\fR and \fIovector[1]\fR, identify the portion of the  first pair, \fIovector[0]\fP and \fIovector[1]\fP, identify the portion of the
1199  subject string matched by the entire pattern. The next pair is used for the  subject string matched by the entire pattern. The next pair is used for the
1200  first capturing subpattern, and so on. The value returned by \fBpcre_exec()\fR  first capturing subpattern, and so on. The value returned by \fBpcre_exec()\fP
1201  is the number of pairs that have been set. If there are no capturing  is the number of pairs that have been set. If there are no capturing
1202  subpatterns, the return value from a successful match is 1, indicating that  subpatterns, the return value from a successful match is 1, indicating that
1203  just the first pair of offsets has been set.  just the first pair of offsets has been set.
1204    .P
1205  Some convenience functions are provided for extracting the captured substrings  Some convenience functions are provided for extracting the captured substrings
1206  as separate strings. These are described in the following section.  as separate strings. These are described in the following section.
1207    .P
1208  It is possible for an capturing subpattern number \fIn+1\fR to match some  It is possible for an capturing subpattern number \fIn+1\fP to match some
1209  part of the subject when subpattern \fIn\fR has not been used at all. For  part of the subject when subpattern \fIn\fP has not been used at all. For
1210  example, if the string "abc" is matched against the pattern (a|(z))(bc)  example, if the string "abc" is matched against the pattern (a|(z))(bc)
1211  subpatterns 1 and 3 are matched, but 2 is not. When this happens, both offset  subpatterns 1 and 3 are matched, but 2 is not. When this happens, both offset
1212  values corresponding to the unused subpattern are set to -1.  values corresponding to the unused subpattern are set to -1.
1213    .P
1214  If a capturing subpattern is matched repeatedly, it is the last portion of the  If a capturing subpattern is matched repeatedly, it is the last portion of the
1215  string that it matched that gets returned.  string that it matched that is returned.
1216    .P
1217  If the vector is too small to hold all the captured substrings, it is used as  If the vector is too small to hold all the captured substring offsets, it is
1218  far as possible (up to two-thirds of its length), and the function returns a  used as far as possible (up to two-thirds of its length), and the function
1219  value of zero. In particular, if the substring offsets are not of interest,  returns a value of zero. In particular, if the substring offsets are not of
1220  \fBpcre_exec()\fR may be called with \fIovector\fR passed as NULL and  interest, \fBpcre_exec()\fP may be called with \fIovector\fP passed as NULL and
1221  \fIovecsize\fR as zero. However, if the pattern contains back references and  \fIovecsize\fP as zero. However, if the pattern contains back references and
1222  the \fIovector\fR isn't big enough to remember the related substrings, PCRE has  the \fIovector\fP is not big enough to remember the related substrings, PCRE
1223  to get additional memory for use during matching. Thus it is usually advisable  has to get additional memory for use during matching. Thus it is usually
1224  to supply an \fIovector\fR.  advisable to supply an \fIovector\fP.
1225    .P
1226  Note that \fBpcre_info()\fR can be used to find out how many capturing  Note that \fBpcre_info()\fP can be used to find out how many capturing
1227  subpatterns there are in a compiled pattern. The smallest size for  subpatterns there are in a compiled pattern. The smallest size for
1228  \fIovector\fR that will allow for \fIn\fR captured substrings, in addition to  \fIovector\fP that will allow for \fIn\fP captured substrings, in addition to
1229  the offsets of the substring matched by the whole pattern, is (\fIn\fR+1)*3.  the offsets of the substring matched by the whole pattern, is (\fIn\fP+1)*3.
1230    .
1231  If \fBpcre_exec()\fR fails, it returns a negative number. The following are  .\" HTML <a name="errorlist"></a>
1232    .SS "Return values from \fBpcre_exec()\fP"
1233    .rs
1234    .sp
1235    If \fBpcre_exec()\fP fails, it returns a negative number. The following are
1236  defined in the header file:  defined in the header file:
1237    .sp
1238    PCRE_ERROR_NOMATCH        (-1)    PCRE_ERROR_NOMATCH        (-1)
1239    .sp
1240  The subject string did not match the pattern.  The subject string did not match the pattern.
1241    .sp
1242    PCRE_ERROR_NULL           (-2)    PCRE_ERROR_NULL           (-2)
1243    .sp
1244  Either \fIcode\fR or \fIsubject\fR was passed as NULL, or \fIovector\fR was  Either \fIcode\fP or \fIsubject\fP was passed as NULL, or \fIovector\fP was
1245  NULL and \fIovecsize\fR was not zero.  NULL and \fIovecsize\fP was not zero.
1246    .sp
1247    PCRE_ERROR_BADOPTION      (-3)    PCRE_ERROR_BADOPTION      (-3)
1248    .sp
1249  An unrecognized bit was set in the \fIoptions\fR argument.  An unrecognized bit was set in the \fIoptions\fP argument.
1250    .sp
1251    PCRE_ERROR_BADMAGIC       (-4)    PCRE_ERROR_BADMAGIC       (-4)
1252    .sp
1253  PCRE stores a 4-byte "magic number" at the start of the compiled code, to catch  PCRE stores a 4-byte "magic number" at the start of the compiled code, to catch
1254  the case when it is passed a junk pointer. This is the error it gives when the  the case when it is passed a junk pointer and to detect when a pattern that was
1255  magic number isn't present.  compiled in an environment of one endianness is run in an environment with the
1256    other endianness. This is the error that PCRE gives when the magic number is
1257    not present.
1258    .sp
1259    PCRE_ERROR_UNKNOWN_NODE   (-5)    PCRE_ERROR_UNKNOWN_NODE   (-5)
1260    .sp
1261  While running the pattern match, an unknown item was encountered in the  While running the pattern match, an unknown item was encountered in the
1262  compiled pattern. This error could be caused by a bug in PCRE or by overwriting  compiled pattern. This error could be caused by a bug in PCRE or by overwriting
1263  of the compiled pattern.  of the compiled pattern.
1264    .sp
1265    PCRE_ERROR_NOMEMORY       (-6)    PCRE_ERROR_NOMEMORY       (-6)
1266    .sp
1267  If a pattern contains back references, but the \fIovector\fR that is passed to  If a pattern contains back references, but the \fIovector\fP that is passed to
1268  \fBpcre_exec()\fR is not big enough to remember the referenced substrings, PCRE  \fBpcre_exec()\fP is not big enough to remember the referenced substrings, PCRE
1269  gets a block of memory at the start of matching to use for this purpose. If the  gets a block of memory at the start of matching to use for this purpose. If the
1270  call via \fBpcre_malloc()\fR fails, this error is given. The memory is freed at  call via \fBpcre_malloc()\fP fails, this error is given. The memory is
1271  the end of matching.  automatically freed at the end of matching.
1272    .sp
1273    PCRE_ERROR_NOSUBSTRING    (-7)    PCRE_ERROR_NOSUBSTRING    (-7)
1274    .sp
1275  This error is used by the \fBpcre_copy_substring()\fR,  This error is used by the \fBpcre_copy_substring()\fP,
1276  \fBpcre_get_substring()\fR, and \fBpcre_get_substring_list()\fR functions (see  \fBpcre_get_substring()\fP, and \fBpcre_get_substring_list()\fP functions (see
1277  below). It is never returned by \fBpcre_exec()\fR.  below). It is never returned by \fBpcre_exec()\fP.
1278    .sp
1279    PCRE_ERROR_MATCHLIMIT     (-8)    PCRE_ERROR_MATCHLIMIT     (-8)
1280    .sp
1281  The recursion and backtracking limit, as specified by the \fImatch_limit\fR  The backtracking limit, as specified by the \fImatch_limit\fP field in a
1282  field in a \fBpcre_extra\fR structure (or defaulted) was reached. See the  \fBpcre_extra\fP structure (or defaulted) was reached. See the description
1283    above.
1284    .sp
1285      PCRE_ERROR_RECURSIONLIMIT (-21)
1286    .sp
1287    The internal recursion limit, as specified by the \fImatch_limit_recursion\fP
1288    field in a \fBpcre_extra\fP structure (or defaulted) was reached. See the
1289  description above.  description above.
1290    .sp
1291    PCRE_ERROR_CALLOUT        (-9)    PCRE_ERROR_CALLOUT        (-9)
1292    .sp
1293  This error is never generated by \fBpcre_exec()\fR itself. It is provided for  This error is never generated by \fBpcre_exec()\fP itself. It is provided for
1294  use by callout functions that want to yield a distinctive error code. See the  use by callout functions that want to yield a distinctive error code. See the
1295  \fBpcrecallout\fR documentation for details.  .\" HREF
1296    \fBpcrecallout\fP
1297    PCRE_ERROR_BADUTF8       (-10)  .\"
1298    documentation for details.
1299    .sp
1300      PCRE_ERROR_BADUTF8        (-10)
1301    .sp
1302  A string that contains an invalid UTF-8 byte sequence was passed as a subject.  A string that contains an invalid UTF-8 byte sequence was passed as a subject.
1303    .sp
1304  .SH EXTRACTING CAPTURED SUBSTRINGS BY NUMBER    PCRE_ERROR_BADUTF8_OFFSET (-11)
1305    .sp
1306    The UTF-8 byte sequence that was passed as a subject was valid, but the value
1307    of \fIstartoffset\fP did not point to the beginning of a UTF-8 character.
1308    .sp
1309      PCRE_ERROR_PARTIAL        (-12)
1310    .sp
1311    The subject string did not match, but it did match partially. See the
1312    .\" HREF
1313    \fBpcrepartial\fP
1314    .\"
1315    documentation for details of partial matching.
1316    .sp
1317      PCRE_ERROR_BADPARTIAL     (-13)
1318    .sp
1319    The PCRE_PARTIAL option was used with a compiled pattern containing items that
1320    are not supported for partial matching. See the
1321    .\" HREF
1322    \fBpcrepartial\fP
1323    .\"
1324    documentation for details of partial matching.
1325    .sp
1326      PCRE_ERROR_INTERNAL       (-14)
1327    .sp
1328    An unexpected internal error has occurred. This error could be caused by a bug
1329    in PCRE or by overwriting of the compiled pattern.
1330    .sp
1331      PCRE_ERROR_BADCOUNT       (-15)
1332    .sp
1333    This error is given if the value of the \fIovecsize\fP argument is negative.
1334    .
1335    .
1336    .SH "EXTRACTING CAPTURED SUBSTRINGS BY NUMBER"
1337  .rs  .rs
1338  .sp  .sp
1339  .B int pcre_copy_substring(const char *\fIsubject\fR, int *\fIovector\fR,  .B int pcre_copy_substring(const char *\fIsubject\fP, int *\fIovector\fP,
1340  .ti +5n  .ti +5n
1341  .B int \fIstringcount\fR, int \fIstringnumber\fR, char *\fIbuffer\fR,  .B int \fIstringcount\fP, int \fIstringnumber\fP, char *\fIbuffer\fP,
1342  .ti +5n  .ti +5n
1343  .B int \fIbuffersize\fR);  .B int \fIbuffersize\fP);
1344  .PP  .PP
1345  .br  .br
1346  .B int pcre_get_substring(const char *\fIsubject\fR, int *\fIovector\fR,  .B int pcre_get_substring(const char *\fIsubject\fP, int *\fIovector\fP,
1347  .ti +5n  .ti +5n
1348  .B int \fIstringcount\fR, int \fIstringnumber\fR,  .B int \fIstringcount\fP, int \fIstringnumber\fP,
1349  .ti +5n  .ti +5n
1350  .B const char **\fIstringptr\fR);  .B const char **\fIstringptr\fP);
1351  .PP  .PP
1352  .br  .br
1353  .B int pcre_get_substring_list(const char *\fIsubject\fR,  .B int pcre_get_substring_list(const char *\fIsubject\fP,
1354  .ti +5n  .ti +5n
1355  .B int *\fIovector\fR, int \fIstringcount\fR, "const char ***\fIlistptr\fR);"  .B int *\fIovector\fP, int \fIstringcount\fP, "const char ***\fIlistptr\fP);"
1356  .PP  .PP
1357  Captured substrings can be accessed directly by using the offsets returned by  Captured substrings can be accessed directly by using the offsets returned by
1358  \fBpcre_exec()\fR in \fIovector\fR. For convenience, the functions  \fBpcre_exec()\fP in \fIovector\fP. For convenience, the functions
1359  \fBpcre_copy_substring()\fR, \fBpcre_get_substring()\fR, and  \fBpcre_copy_substring()\fP, \fBpcre_get_substring()\fP, and
1360  \fBpcre_get_substring_list()\fR are provided for extracting captured substrings  \fBpcre_get_substring_list()\fP are provided for extracting captured substrings
1361  as new, separate, zero-terminated strings. These functions identify substrings  as new, separate, zero-terminated strings. These functions identify substrings
1362  by number. The next section describes functions for extracting named  by number. The next section describes functions for extracting named
1363  substrings. A substring that contains a binary zero is correctly extracted and  substrings. A substring that contains a binary zero is correctly extracted and
1364  has a further zero added on the end, but the result is not, of course,  has a further zero added on the end, but the result is not, of course,
1365  a C string.  a C string.
1366    .P
1367  The first three arguments are the same for all three of these functions:  The first three arguments are the same for all three of these functions:
1368  \fIsubject\fR is the subject string which has just been successfully matched,  \fIsubject\fP is the subject string that has just been successfully matched,
1369  \fIovector\fR is a pointer to the vector of integer offsets that was passed to  \fIovector\fP is a pointer to the vector of integer offsets that was passed to
1370  \fBpcre_exec()\fR, and \fIstringcount\fR is the number of substrings that were  \fBpcre_exec()\fP, and \fIstringcount\fP is the number of substrings that were
1371  captured by the match, including the substring that matched the entire regular  captured by the match, including the substring that matched the entire regular
1372  expression. This is the value returned by \fBpcre_exec\fR if it is greater than  expression. This is the value returned by \fBpcre_exec()\fP if it is greater
1373  zero. If \fBpcre_exec()\fR returned zero, indicating that it ran out of space  than zero. If \fBpcre_exec()\fP returned zero, indicating that it ran out of
1374  in \fIovector\fR, the value passed as \fIstringcount\fR should be the size of  space in \fIovector\fP, the value passed as \fIstringcount\fP should be the
1375  the vector divided by three.  number of elements in the vector divided by three.
1376    .P
1377  The functions \fBpcre_copy_substring()\fR and \fBpcre_get_substring()\fR  The functions \fBpcre_copy_substring()\fP and \fBpcre_get_substring()\fP
1378  extract a single substring, whose number is given as \fIstringnumber\fR. A  extract a single substring, whose number is given as \fIstringnumber\fP. A
1379  value of zero extracts the substring that matched the entire pattern, while  value of zero extracts the substring that matched the entire pattern, whereas
1380  higher values extract the captured substrings. For \fBpcre_copy_substring()\fR,  higher values extract the captured substrings. For \fBpcre_copy_substring()\fP,
1381  the string is placed in \fIbuffer\fR, whose length is given by  the string is placed in \fIbuffer\fP, whose length is given by
1382  \fIbuffersize\fR, while for \fBpcre_get_substring()\fR a new block of memory is  \fIbuffersize\fP, while for \fBpcre_get_substring()\fP a new block of memory is
1383  obtained via \fBpcre_malloc\fR, and its address is returned via  obtained via \fBpcre_malloc\fP, and its address is returned via
1384  \fIstringptr\fR. The yield of the function is the length of the string, not  \fIstringptr\fP. The yield of the function is the length of the string, not
1385  including the terminating zero, or one of  including the terminating zero, or one of
1386    .sp
1387    PCRE_ERROR_NOMEMORY       (-6)    PCRE_ERROR_NOMEMORY       (-6)
1388    .sp
1389  The buffer was too small for \fBpcre_copy_substring()\fR, or the attempt to get  The buffer was too small for \fBpcre_copy_substring()\fP, or the attempt to get
1390  memory failed for \fBpcre_get_substring()\fR.  memory failed for \fBpcre_get_substring()\fP.
1391    .sp
1392    PCRE_ERROR_NOSUBSTRING    (-7)    PCRE_ERROR_NOSUBSTRING    (-7)
1393    .sp
1394  There is no substring whose number is \fIstringnumber\fR.  There is no substring whose number is \fIstringnumber\fP.
1395    .P
1396  The \fBpcre_get_substring_list()\fR function extracts all available substrings  The \fBpcre_get_substring_list()\fP function extracts all available substrings
1397  and builds a list of pointers to them. All this is done in a single block of  and builds a list of pointers to them. All this is done in a single block of
1398  memory which is obtained via \fBpcre_malloc\fR. The address of the memory block  memory that is obtained via \fBpcre_malloc\fP. The address of the memory block
1399  is returned via \fIlistptr\fR, which is also the start of the list of string  is returned via \fIlistptr\fP, which is also the start of the list of string
1400  pointers. The end of the list is marked by a NULL pointer. The yield of the  pointers. The end of the list is marked by a NULL pointer. The yield of the
1401  function is zero if all went well, or  function is zero if all went well, or
1402    .sp
1403    PCRE_ERROR_NOMEMORY       (-6)    PCRE_ERROR_NOMEMORY       (-6)
1404    .sp
1405  if the attempt to get the memory block failed.  if the attempt to get the memory block failed.
1406    .P
1407  When any of these functions encounter a substring that is unset, which can  When any of these functions encounter a substring that is unset, which can
1408  happen when capturing subpattern number \fIn+1\fR matches some part of the  happen when capturing subpattern number \fIn+1\fP matches some part of the
1409  subject, but subpattern \fIn\fR has not been used at all, they return an empty  subject, but subpattern \fIn\fP has not been used at all, they return an empty
1410  string. This can be distinguished from a genuine zero-length substring by  string. This can be distinguished from a genuine zero-length substring by
1411  inspecting the appropriate offset in \fIovector\fR, which is negative for unset  inspecting the appropriate offset in \fIovector\fP, which is negative for unset
1412  substrings.  substrings.
1413    .P
1414  The two convenience functions \fBpcre_free_substring()\fR and  The two convenience functions \fBpcre_free_substring()\fP and
1415  \fBpcre_free_substring_list()\fR can be used to free the memory returned by  \fBpcre_free_substring_list()\fP can be used to free the memory returned by
1416  a previous call of \fBpcre_get_substring()\fR or  a previous call of \fBpcre_get_substring()\fP or
1417  \fBpcre_get_substring_list()\fR, respectively. They do nothing more than call  \fBpcre_get_substring_list()\fP, respectively. They do nothing more than call
1418  the function pointed to by \fBpcre_free\fR, which of course could be called  the function pointed to by \fBpcre_free\fP, which of course could be called
1419  directly from a C program. However, PCRE is used in some situations where it is  directly from a C program. However, PCRE is used in some situations where it is
1420  linked via a special interface to another programming language which cannot use  linked via a special interface to another programming language which cannot use
1421  \fBpcre_free\fR directly; it is for these cases that the functions are  \fBpcre_free\fP directly; it is for these cases that the functions are
1422  provided.  provided.
1423    .
1424  .SH EXTRACTING CAPTURED SUBSTRINGS BY NAME  .
1425    .SH "EXTRACTING CAPTURED SUBSTRINGS BY NAME"
1426  .rs  .rs
1427  .sp  .sp
1428  .B int pcre_copy_named_substring(const pcre *\fIcode\fR,  .B int pcre_get_stringnumber(const pcre *\fIcode\fP,
 .ti +5n  
 .B const char *\fIsubject\fR, int *\fIovector\fR,  
1429  .ti +5n  .ti +5n
1430  .B int \fIstringcount\fR, const char *\fIstringname\fR,  .B const char *\fIname\fP);
 .ti +5n  
 .B char *\fIbuffer\fR, int \fIbuffersize\fR);  
1431  .PP  .PP
1432  .br  .br
1433  .B int pcre_get_stringnumber(const pcre *\fIcode\fR,  .B int pcre_copy_named_substring(const pcre *\fIcode\fP,
1434    .ti +5n
1435    .B const char *\fIsubject\fP, int *\fIovector\fP,
1436  .ti +5n  .ti +5n
1437  .B const char *\fIname\fR);  .B int \fIstringcount\fP, const char *\fIstringname\fP,
1438    .ti +5n
1439    .B char *\fIbuffer\fP, int \fIbuffersize\fP);
1440  .PP  .PP
1441  .br  .br
1442  .B int pcre_get_named_substring(const pcre *\fIcode\fR,  .B int pcre_get_named_substring(const pcre *\fIcode\fP,
1443  .ti +5n  .ti +5n
1444  .B const char *\fIsubject\fR, int *\fIovector\fR,  .B const char *\fIsubject\fP, int *\fIovector\fP,
1445  .ti +5n  .ti +5n
1446  .B int \fIstringcount\fR, const char *\fIstringname\fR,  .B int \fIstringcount\fP, const char *\fIstringname\fP,
1447  .ti +5n  .ti +5n
1448  .B const char **\fIstringptr\fR);  .B const char **\fIstringptr\fP);
1449  .PP  .PP
1450  To extract a substring by name, you first have to find associated number. This  To extract a substring by name, you first have to find associated number.
1451  can be done by calling \fBpcre_get_stringnumber()\fR. The first argument is the  For example, for this pattern
1452  compiled pattern, and the second is the name. For example, for this pattern  .sp
1453      (a+)b(?P<xxx>\ed+)...
1454    ab(?<xxx>\\d+)...  .sp
1455    the number of the subpattern called "xxx" is 2. You can find the number from
1456  the number of the subpattern called "xxx" is 1. Given the number, you can then  the name by calling \fBpcre_get_stringnumber()\fP. The first argument is the
1457  extract the substring directly, or use one of the functions described in the  compiled pattern, and the second is the name. The yield of the function is the
1458  previous section. For convenience, there are also two functions that do the  subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no subpattern of
1459  whole job.  that name.
1460    .P
1461  Most of the arguments of \fIpcre_copy_named_substring()\fR and  Given the number, you can extract the substring directly, or use one of the
1462  \fIpcre_get_named_substring()\fR are the same as those for the functions that  functions described in the previous section. For convenience, there are also
1463  extract by number, and so are not re-described here. There are just two  two functions that do the whole job.
1464  differences.  .P
1465    Most of the arguments of \fIpcre_copy_named_substring()\fP and
1466    \fIpcre_get_named_substring()\fP are the same as those for the similarly named
1467    functions that extract by number. As these are described in the previous
1468    section, they are not re-described here. There are just two differences:
1469    .P
1470  First, instead of a substring number, a substring name is given. Second, there  First, instead of a substring number, a substring name is given. Second, there
1471  is an extra argument, given at the start, which is a pointer to the compiled  is an extra argument, given at the start, which is a pointer to the compiled
1472  pattern. This is needed in order to gain access to the name-to-number  pattern. This is needed in order to gain access to the name-to-number
1473  translation table.  translation table.
1474    .P
1475  These functions call \fBpcre_get_stringnumber()\fR, and if it succeeds, they  These functions call \fBpcre_get_stringnumber()\fP, and if it succeeds, they
1476  then call \fIpcre_copy_substring()\fR or \fIpcre_get_substring()\fR, as  then call \fIpcre_copy_substring()\fP or \fIpcre_get_substring()\fP, as
1477  appropriate.  appropriate.
1478    .
1479    .
1480    .SH "FINDING ALL POSSIBLE MATCHES"
1481    .rs
1482    .sp
1483    The traditional matching function uses a similar algorithm to Perl, which stops
1484    when it finds the first match, starting at a given point in the subject. If you
1485    want to find all possible matches, or the longest possible match, consider
1486    using the alternative matching function (see below) instead. If you cannot use
1487    the alternative function, but still need to find all possible matches, you
1488    can kludge it up by making use of the callout facility, which is described in
1489    the
1490    .\" HREF
1491    \fBpcrecallout\fP
1492    .\"
1493    documentation.
1494    .P
1495    What you have to do is to insert a callout right at the end of the pattern.
1496    When your callout function is called, extract and save the current matched
1497    substring. Then return 1, which forces \fBpcre_exec()\fP to backtrack and try
1498    other alternatives. Ultimately, when it runs out of matches, \fBpcre_exec()\fP
1499    will yield PCRE_ERROR_NOMATCH.
1500    .
1501    .
1502    .\" HTML <a name="dfamatch"></a>
1503    .SH "MATCHING A PATTERN: THE ALTERNATIVE FUNCTION"
1504    .rs
1505    .sp
1506    .B int pcre_dfa_exec(const pcre *\fIcode\fP, "const pcre_extra *\fIextra\fP,"
1507    .ti +5n
1508    .B "const char *\fIsubject\fP," int \fIlength\fP, int \fIstartoffset\fP,
1509    .ti +5n
1510    .B int \fIoptions\fP, int *\fIovector\fP, int \fIovecsize\fP,
1511    .ti +5n
1512    .B int *\fIworkspace\fP, int \fIwscount\fP);
1513    .P
1514    The function \fBpcre_dfa_exec()\fP is called to match a subject string against
1515    a compiled pattern, using a "DFA" matching algorithm. This has different
1516    characteristics to the normal algorithm, and is not compatible with Perl. Some
1517    of the features of PCRE patterns are not supported. Nevertheless, there are
1518    times when this kind of matching can be useful. For a discussion of the two
1519    matching algorithms, see the
1520    .\" HREF
1521    \fBpcrematching\fP
1522    .\"
1523    documentation.
1524    .P
1525    The arguments for the \fBpcre_dfa_exec()\fP function are the same as for
1526    \fBpcre_exec()\fP, plus two extras. The \fIovector\fP argument is used in a
1527    different way, and this is described below. The other common arguments are used
1528    in the same way as for \fBpcre_exec()\fP, so their description is not repeated
1529    here.
1530    .P
1531    The two additional arguments provide workspace for the function. The workspace
1532    vector should contain at least 20 elements. It is used for keeping track of
1533    multiple paths through the pattern tree. More workspace will be needed for
1534    patterns and subjects where there are a lot of possible matches.
1535    .P
1536    Here is an example of a simple call to \fBpcre_dfa_exec()\fP:
1537    .sp
1538      int rc;
1539      int ovector[10];
1540      int wspace[20];
1541      rc = pcre_dfa_exec(
1542        re,             /* result of pcre_compile() */
1543        NULL,           /* we didn't study the pattern */
1544        "some string",  /* the subject string */
1545        11,             /* the length of the subject string */
1546        0,              /* start at offset 0 in the subject */
1547        0,              /* default options */
1548        ovector,        /* vector of integers for substring information */
1549        10,             /* number of elements (NOT size in bytes) */
1550        wspace,         /* working space vector */
1551        20);            /* number of elements (NOT size in bytes) */
1552    .
1553    .SS "Option bits for \fBpcre_dfa_exec()\fP"
1554    .rs
1555    .sp
1556    The unused bits of the \fIoptions\fP argument for \fBpcre_dfa_exec()\fP must be
1557    zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NOTBOL,
1558    PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL,
1559    PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last three of these are
1560    the same as for \fBpcre_exec()\fP, so their description is not repeated here.
1561    .sp
1562      PCRE_PARTIAL
1563    .sp
1564    This has the same general effect as it does for \fBpcre_exec()\fP, but the
1565    details are slightly different. When PCRE_PARTIAL is set for
1566    \fBpcre_dfa_exec()\fP, the return code PCRE_ERROR_NOMATCH is converted into
1567    PCRE_ERROR_PARTIAL if the end of the subject is reached, there have been no
1568    complete matches, but there is still at least one matching possibility. The
1569    portion of the string that provided the partial match is set as the first
1570    matching string.
1571    .sp
1572      PCRE_DFA_SHORTEST
1573    .sp
1574    Setting the PCRE_DFA_SHORTEST option causes the matching algorithm to stop as
1575    soon as it has found one match. Because of the way the DFA algorithm works,
1576    this is necessarily the shortest possible match at the first possible matching
1577    point in the subject string.
1578    .sp
1579      PCRE_DFA_RESTART
1580    .sp
1581    When \fBpcre_dfa_exec()\fP is called with the PCRE_PARTIAL option, and returns
1582    a partial match, it is possible to call it again, with additional subject
1583    characters, and have it continue with the same match. The PCRE_DFA_RESTART
1584    option requests this action; when it is set, the \fIworkspace\fP and
1585    \fIwscount\fP options must reference the same vector as before because data
1586    about the match so far is left in them after a partial match. There is more
1587    discussion of this facility in the
1588    .\" HREF
1589    \fBpcrepartial\fP
1590    .\"
1591    documentation.
1592    .
1593    .SS "Successful returns from \fBpcre_dfa_exec()\fP"
1594    .rs
1595    .sp
1596    When \fBpcre_dfa_exec()\fP succeeds, it may have matched more than one
1597    substring in the subject. Note, however, that all the matches from one run of
1598    the function start at the same point in the subject. The shorter matches are
1599    all initial substrings of the longer matches. For example, if the pattern
1600    .sp
1601      <.*>
1602    .sp
1603    is matched against the string
1604    .sp
1605      This is <something> <something else> <something further> no more
1606    .sp
1607    the three matched strings are
1608    .sp
1609      <something>
1610      <something> <something else>
1611      <something> <something else> <something further>
1612    .sp
1613    On success, the yield of the function is a number greater than zero, which is
1614    the number of matched substrings. The substrings themselves are returned in
1615    \fIovector\fP. Each string uses two elements; the first is the offset to the
1616    start, and the second is the offset to the end. All the strings have the same
1617    start offset. (Space could have been saved by giving this only once, but it was
1618    decided to retain some compatibility with the way \fBpcre_exec()\fP returns
1619    data, even though the meaning of the strings is different.)
1620    .P
1621    The strings are returned in reverse order of length; that is, the longest
1622    matching string is given first. If there were too many matches to fit into
1623    \fIovector\fP, the yield of the function is zero, and the vector is filled with
1624    the longest matches.
1625    .
1626    .SS "Error returns from \fBpcre_dfa_exec()\fP"
1627    .rs
1628    .sp
1629    The \fBpcre_dfa_exec()\fP function returns a negative number when it fails.
1630    Many of the errors are the same as for \fBpcre_exec()\fP, and these are
1631    described
1632    .\" HTML <a href="#errorlist">
1633    .\" </a>
1634    above.
1635    .\"
1636    There are in addition the following errors that are specific to
1637    \fBpcre_dfa_exec()\fP:
1638    .sp
1639      PCRE_ERROR_DFA_UITEM      (-16)
1640    .sp
1641    This return is given if \fBpcre_dfa_exec()\fP encounters an item in the pattern
1642    that it does not support, for instance, the use of \eC or a back reference.
1643    .sp
1644      PCRE_ERROR_DFA_UCOND      (-17)
1645    .sp
1646    This return is given if \fBpcre_dfa_exec()\fP encounters a condition item in a
1647    pattern that uses a back reference for the condition. This is not supported.
1648    .sp
1649      PCRE_ERROR_DFA_UMLIMIT    (-18)
1650    .sp
1651    This return is given if \fBpcre_dfa_exec()\fP is called with an \fIextra\fP
1652    block that contains a setting of the \fImatch_limit\fP field. This is not
1653    supported (it is meaningless).
1654    .sp
1655      PCRE_ERROR_DFA_WSSIZE     (-19)
1656    .sp
1657    This return is given if \fBpcre_dfa_exec()\fP runs out of space in the
1658    \fIworkspace\fP vector.
1659    .sp
1660      PCRE_ERROR_DFA_RECURSE    (-20)
1661    .sp
1662    When a recursive subpattern is processed, the matching function calls itself
1663    recursively, using private vectors for \fIovector\fP and \fIworkspace\fP. This
1664    error is given if the output vector is not large enough. This should be
1665    extremely rare, as a vector of size 1000 is used.
1666    .P
1667  .in 0  .in 0
1668  Last updated: 20 August 2003  Last updated: 18 January 2006
1669  .br  .br
1670  Copyright (c) 1997-2003 University of Cambridge.  Copyright (c) 1997-2006 University of Cambridge.

Legend:
Removed from v.71  
changed lines
  Added in v.87

  ViewVC Help
Powered by ViewVC 1.1.5