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

Contents of /code/trunk/doc/pcreposix.3

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (hide annotations) (download)
Sat Feb 24 21:39:33 2007 UTC (6 years, 2 months ago) by nigel
File size: 5888 byte(s)
Load pcre-3.3 into code/trunk.

1 nigel 41 .TH PCRE 3
2     .SH NAME
3     pcreposix - POSIX API for Perl-compatible regular expressions.
4     .SH SYNOPSIS
5     .B #include <pcreposix.h>
6     .PP
7     .SM
8     .br
9     .B int regcomp(regex_t *\fIpreg\fR, const char *\fIpattern\fR,
10     .ti +5n
11     .B int \fIcflags\fR);
12     .PP
13     .br
14     .B int regexec(regex_t *\fIpreg\fR, const char *\fIstring\fR,
15     .ti +5n
16     .B size_t \fInmatch\fR, regmatch_t \fIpmatch\fR[], int \fIeflags\fR);
17     .PP
18     .br
19     .B size_t regerror(int \fIerrcode\fR, const regex_t *\fIpreg\fR,
20     .ti +5n
21     .B char *\fIerrbuf\fR, size_t \fIerrbuf_size\fR);
22     .PP
23     .br
24     .B void regfree(regex_t *\fIpreg\fR);
25    
26    
27     .SH DESCRIPTION
28     This set of functions provides a POSIX-style API to the PCRE regular expression
29     package. See the \fBpcre\fR documentation for a description of the native API,
30     which contains additional functionality.
31    
32     The functions described here are just wrapper functions that ultimately call
33     the native API. Their prototypes are defined in the \fBpcreposix.h\fR header
34     file, and on Unix systems the library itself is called \fBpcreposix.a\fR, so
35     can be accessed by adding \fB-lpcreposix\fR to the command for linking an
36     application which uses them. Because the POSIX functions call the native ones,
37     it is also necessary to add \fR-lpcre\fR.
38    
39 nigel 43 I have implemented only those option bits that can be reasonably mapped to PCRE
40     native options. In addition, the options REG_EXTENDED and REG_NOSUB are defined
41     with the value zero. They have no effect, but since programs that are written
42     to the POSIX interface often use them, this makes it easier to slot in PCRE as
43     a replacement library. Other POSIX options are not even defined.
44 nigel 41
45     When PCRE is called via these functions, it is only the API that is POSIX-like
46     in style. The syntax and semantics of the regular expressions themselves are
47     still those of Perl, subject to the setting of various PCRE options, as
48     described below.
49    
50     The header for these functions is supplied as \fBpcreposix.h\fR to avoid any
51     potential clash with other POSIX libraries. It can, of course, be renamed or
52     aliased as \fBregex.h\fR, which is the "correct" name. It provides two
53     structure types, \fIregex_t\fR for compiled internal forms, and
54     \fIregmatch_t\fR for returning captured substrings. It also defines some
55     constants whose names start with "REG_"; these are used for setting options and
56     identifying error codes.
57    
58    
59     .SH COMPILING A PATTERN
60    
61     The function \fBregcomp()\fR is called to compile a pattern into an
62     internal form. The pattern is a C string terminated by a binary zero, and
63     is passed in the argument \fIpattern\fR. The \fIpreg\fR argument is a pointer
64     to a regex_t structure which is used as a base for storing information about
65     the compiled expression.
66    
67     The argument \fIcflags\fR is either zero, or contains one or more of the bits
68     defined by the following macros:
69    
70     REG_ICASE
71    
72     The PCRE_CASELESS option is set when the expression is passed for compilation
73     to the native function.
74    
75     REG_NEWLINE
76    
77     The PCRE_MULTILINE option is set when the expression is passed for compilation
78     to the native function.
79    
80 nigel 49 In the absence of these flags, no options are passed to the native function.
81     This means the the regex is compiled with PCRE default semantics. In
82     particular, the way it handles newline characters in the subject string is the
83     Perl way, not the POSIX way. Note that setting PCRE_MULTILINE has only
84     \fIsome\fR of the effects specified for REG_NEWLINE. It does not affect the way
85     newlines are matched by . (they aren't) or a negative class such as [^a] (they
86     are).
87    
88 nigel 41 The yield of \fBregcomp()\fR is zero on success, and non-zero otherwise. The
89     \fIpreg\fR structure is filled in on success, and one member of the structure
90     is publicized: \fIre_nsub\fR contains the number of capturing subpatterns in
91     the regular expression. Various error codes are defined in the header file.
92    
93    
94     .SH MATCHING A PATTERN
95     The function \fBregexec()\fR is called to match a pre-compiled pattern
96     \fIpreg\fR against a given \fIstring\fR, which is terminated by a zero byte,
97     subject to the options in \fIeflags\fR. These can be:
98    
99     REG_NOTBOL
100    
101     The PCRE_NOTBOL option is set when calling the underlying PCRE matching
102     function.
103    
104     REG_NOTEOL
105    
106     The PCRE_NOTEOL option is set when calling the underlying PCRE matching
107     function.
108    
109     The portion of the string that was matched, and also any captured substrings,
110     are returned via the \fIpmatch\fR argument, which points to an array of
111     \fInmatch\fR structures of type \fIregmatch_t\fR, containing the members
112     \fIrm_so\fR and \fIrm_eo\fR. These contain the offset to the first character of
113     each substring and the offset to the first character after the end of each
114     substring, respectively. The 0th element of the vector relates to the entire
115     portion of \fIstring\fR that was matched; subsequent elements relate to the
116     capturing subpatterns of the regular expression. Unused entries in the array
117     have both structure members set to -1.
118    
119     A successful match yields a zero return; various error codes are defined in the
120     header file, of which REG_NOMATCH is the "expected" failure code.
121    
122    
123     .SH ERROR MESSAGES
124     The \fBregerror()\fR function maps a non-zero errorcode from either
125     \fBregcomp\fR or \fBregexec\fR to a printable message. If \fIpreg\fR is not
126     NULL, the error should have arisen from the use of that structure. A message
127     terminated by a binary zero is placed in \fIerrbuf\fR. The length of the
128     message, including the zero, is limited to \fIerrbuf_size\fR. The yield of the
129     function is the size of buffer needed to hold the whole message.
130    
131    
132     .SH STORAGE
133     Compiling a regular expression causes memory to be allocated and associated
134     with the \fIpreg\fR structure. The function \fBregfree()\fR frees all such
135     memory, after which \fIpreg\fR may no longer be used as a compiled expression.
136    
137    
138     .SH AUTHOR
139     Philip Hazel <ph10@cam.ac.uk>
140     .br
141     University Computing Service,
142     .br
143     New Museums Site,
144     .br
145     Cambridge CB2 3QG, England.
146     .br
147     Phone: +44 1223 334714
148    
149 nigel 49 Copyright (c) 1997-2000 University of Cambridge.

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12