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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 43 - (show annotations) (download)
Sat Feb 24 21:39:21 2007 UTC (7 years, 5 months ago) by nigel
File size: 5426 byte(s)
Load pcre-3.0 into code/trunk.

1 .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 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
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 The yield of \fBregcomp()\fR is zero on success, and non-zero otherwise. The
81 \fIpreg\fR structure is filled in on success, and one member of the structure
82 is publicized: \fIre_nsub\fR contains the number of capturing subpatterns in
83 the regular expression. Various error codes are defined in the header file.
84
85
86 .SH MATCHING A PATTERN
87 The function \fBregexec()\fR is called to match a pre-compiled pattern
88 \fIpreg\fR against a given \fIstring\fR, which is terminated by a zero byte,
89 subject to the options in \fIeflags\fR. These can be:
90
91 REG_NOTBOL
92
93 The PCRE_NOTBOL option is set when calling the underlying PCRE matching
94 function.
95
96 REG_NOTEOL
97
98 The PCRE_NOTEOL option is set when calling the underlying PCRE matching
99 function.
100
101 The portion of the string that was matched, and also any captured substrings,
102 are returned via the \fIpmatch\fR argument, which points to an array of
103 \fInmatch\fR structures of type \fIregmatch_t\fR, containing the members
104 \fIrm_so\fR and \fIrm_eo\fR. These contain the offset to the first character of
105 each substring and the offset to the first character after the end of each
106 substring, respectively. The 0th element of the vector relates to the entire
107 portion of \fIstring\fR that was matched; subsequent elements relate to the
108 capturing subpatterns of the regular expression. Unused entries in the array
109 have both structure members set to -1.
110
111 A successful match yields a zero return; various error codes are defined in the
112 header file, of which REG_NOMATCH is the "expected" failure code.
113
114
115 .SH ERROR MESSAGES
116 The \fBregerror()\fR function maps a non-zero errorcode from either
117 \fBregcomp\fR or \fBregexec\fR to a printable message. If \fIpreg\fR is not
118 NULL, the error should have arisen from the use of that structure. A message
119 terminated by a binary zero is placed in \fIerrbuf\fR. The length of the
120 message, including the zero, is limited to \fIerrbuf_size\fR. The yield of the
121 function is the size of buffer needed to hold the whole message.
122
123
124 .SH STORAGE
125 Compiling a regular expression causes memory to be allocated and associated
126 with the \fIpreg\fR structure. The function \fBregfree()\fR frees all such
127 memory, after which \fIpreg\fR may no longer be used as a compiled expression.
128
129
130 .SH AUTHOR
131 Philip Hazel <ph10@cam.ac.uk>
132 .br
133 University Computing Service,
134 .br
135 New Museums Site,
136 .br
137 Cambridge CB2 3QG, England.
138 .br
139 Phone: +44 1223 334714
140
141 Copyright (c) 1997-1999 University of Cambridge.

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12