Correcting some typos, and an obsolete comment.
[privoxy.git] / pcre / doc / pcreposix.html
1 <HTML>\r
2 <HEAD>\r
3 <TITLE>pcreposix specification</TITLE>\r
4 </HEAD>\r
5 <body bgcolor="#FFFFFF" text="#00005A">\r
6 <H1>pcreposix specification</H1>\r
7 This HTML document has been generated automatically from the original man page.\r
8 If there is any nonsense in it, please consult the man page in case the\r
9 conversion went wrong.\r
10 <UL>\r
11 <LI><A NAME="TOC1" HREF="#SEC1">NAME</A>\r
12 <LI><A NAME="TOC2" HREF="#SEC2">SYNOPSIS</A>\r
13 <LI><A NAME="TOC3" HREF="#SEC3">DESCRIPTION</A>\r
14 <LI><A NAME="TOC4" HREF="#SEC4">COMPILING A PATTERN</A>\r
15 <LI><A NAME="TOC5" HREF="#SEC5">MATCHING A PATTERN</A>\r
16 <LI><A NAME="TOC6" HREF="#SEC6">ERROR MESSAGES</A>\r
17 <LI><A NAME="TOC7" HREF="#SEC7">STORAGE</A>\r
18 <LI><A NAME="TOC8" HREF="#SEC8">AUTHOR</A>\r
19 </UL>\r
20 <LI><A NAME="SEC1" HREF="#TOC1">NAME</A>\r
21 <P>\r
22 pcreposix - POSIX API for Perl-compatible regular expressions.\r
23 </P>\r
24 <LI><A NAME="SEC2" HREF="#TOC1">SYNOPSIS</A>\r
25 <P>\r
26 <B>#include &#60;pcreposix.h&#62;</B>\r
27 </P>\r
28 <P>\r
29 <B>int regcomp(regex_t *<I>preg</I>, const char *<I>pattern</I>,</B>\r
30 <B>int <I>cflags</I>);</B>\r
31 </P>\r
32 <P>\r
33 <B>int regexec(regex_t *<I>preg</I>, const char *<I>string</I>,</B>\r
34 <B>size_t <I>nmatch</I>, regmatch_t <I>pmatch</I>[], int <I>eflags</I>);</B>\r
35 </P>\r
36 <P>\r
37 <B>size_t regerror(int <I>errcode</I>, const regex_t *<I>preg</I>,</B>\r
38 <B>char *<I>errbuf</I>, size_t <I>errbuf_size</I>);</B>\r
39 </P>\r
40 <P>\r
41 <B>void regfree(regex_t *<I>preg</I>);</B>\r
42 </P>\r
43 <LI><A NAME="SEC3" HREF="#TOC1">DESCRIPTION</A>\r
44 <P>\r
45 This set of functions provides a POSIX-style API to the PCRE regular expression\r
46 package. See the <B>pcre</B> documentation for a description of the native API,\r
47 which contains additional functionality.\r
48 </P>\r
49 <P>\r
50 The functions described here are just wrapper functions that ultimately call\r
51 the native API. Their prototypes are defined in the <B>pcreposix.h</B> header\r
52 file, and on Unix systems the library itself is called <B>pcreposix.a</B>, so\r
53 can be accessed by adding <B>-lpcreposix</B> to the command for linking an\r
54 application which uses them. Because the POSIX functions call the native ones,\r
55 it is also necessary to add \fR-lpcre\fR.\r
56 </P>\r
57 <P>\r
58 I have implemented only those option bits that can be reasonably mapped to PCRE\r
59 native options. In addition, the options REG_EXTENDED and REG_NOSUB are defined\r
60 with the value zero. They have no effect, but since programs that are written\r
61 to the POSIX interface often use them, this makes it easier to slot in PCRE as\r
62 a replacement library. Other POSIX options are not even defined.\r
63 </P>\r
64 <P>\r
65 When PCRE is called via these functions, it is only the API that is POSIX-like\r
66 in style. The syntax and semantics of the regular expressions themselves are\r
67 still those of Perl, subject to the setting of various PCRE options, as\r
68 described below.\r
69 </P>\r
70 <P>\r
71 The header for these functions is supplied as <B>pcreposix.h</B> to avoid any\r
72 potential clash with other POSIX libraries. It can, of course, be renamed or\r
73 aliased as <B>regex.h</B>, which is the "correct" name. It provides two\r
74 structure types, <I>regex_t</I> for compiled internal forms, and\r
75 <I>regmatch_t</I> for returning captured substrings. It also defines some\r
76 constants whose names start with "REG_"; these are used for setting options and\r
77 identifying error codes.\r
78 </P>\r
79 <LI><A NAME="SEC4" HREF="#TOC1">COMPILING A PATTERN</A>\r
80 <P>\r
81 The function <B>regcomp()</B> is called to compile a pattern into an\r
82 internal form. The pattern is a C string terminated by a binary zero, and\r
83 is passed in the argument <I>pattern</I>. The <I>preg</I> argument is a pointer\r
84 to a regex_t structure which is used as a base for storing information about\r
85 the compiled expression.\r
86 </P>\r
87 <P>\r
88 The argument <I>cflags</I> is either zero, or contains one or more of the bits\r
89 defined by the following macros:\r
90 </P>\r
91 <P>\r
92 <PRE>\r
93   REG_ICASE\r
94 </PRE>\r
95 </P>\r
96 <P>\r
97 The PCRE_CASELESS option is set when the expression is passed for compilation\r
98 to the native function.\r
99 </P>\r
100 <P>\r
101 <PRE>\r
102   REG_NEWLINE\r
103 </PRE>\r
104 </P>\r
105 <P>\r
106 The PCRE_MULTILINE option is set when the expression is passed for compilation\r
107 to the native function.\r
108 </P>\r
109 <P>\r
110 In the absence of these flags, no options are passed to the native function.\r
111 This means the the regex is compiled with PCRE default semantics. In\r
112 particular, the way it handles newline characters in the subject string is the\r
113 Perl way, not the POSIX way. Note that setting PCRE_MULTILINE has only\r
114 <I>some</I> of the effects specified for REG_NEWLINE. It does not affect the way\r
115 newlines are matched by . (they aren't) or a negative class such as [^a] (they\r
116 are).\r
117 </P>\r
118 <P>\r
119 The yield of <B>regcomp()</B> is zero on success, and non-zero otherwise. The\r
120 <I>preg</I> structure is filled in on success, and one member of the structure\r
121 is publicized: <I>re_nsub</I> contains the number of capturing subpatterns in\r
122 the regular expression. Various error codes are defined in the header file.\r
123 </P>\r
124 <LI><A NAME="SEC5" HREF="#TOC1">MATCHING A PATTERN</A>\r
125 <P>\r
126 The function <B>regexec()</B> is called to match a pre-compiled pattern\r
127 <I>preg</I> against a given <I>string</I>, which is terminated by a zero byte,\r
128 subject to the options in <I>eflags</I>. These can be:\r
129 </P>\r
130 <P>\r
131 <PRE>\r
132   REG_NOTBOL\r
133 </PRE>\r
134 </P>\r
135 <P>\r
136 The PCRE_NOTBOL option is set when calling the underlying PCRE matching\r
137 function.\r
138 </P>\r
139 <P>\r
140 <PRE>\r
141   REG_NOTEOL\r
142 </PRE>\r
143 </P>\r
144 <P>\r
145 The PCRE_NOTEOL option is set when calling the underlying PCRE matching\r
146 function.\r
147 </P>\r
148 <P>\r
149 The portion of the string that was matched, and also any captured substrings,\r
150 are returned via the <I>pmatch</I> argument, which points to an array of\r
151 <I>nmatch</I> structures of type <I>regmatch_t</I>, containing the members\r
152 <I>rm_so</I> and <I>rm_eo</I>. These contain the offset to the first character of\r
153 each substring and the offset to the first character after the end of each\r
154 substring, respectively. The 0th element of the vector relates to the entire\r
155 portion of <I>string</I> that was matched; subsequent elements relate to the\r
156 capturing subpatterns of the regular expression. Unused entries in the array\r
157 have both structure members set to -1.\r
158 </P>\r
159 <P>\r
160 A successful match yields a zero return; various error codes are defined in the\r
161 header file, of which REG_NOMATCH is the "expected" failure code.\r
162 </P>\r
163 <LI><A NAME="SEC6" HREF="#TOC1">ERROR MESSAGES</A>\r
164 <P>\r
165 The <B>regerror()</B> function maps a non-zero errorcode from either\r
166 <B>regcomp</B> or <B>regexec</B> to a printable message. If <I>preg</I> is not\r
167 NULL, the error should have arisen from the use of that structure. A message\r
168 terminated by a binary zero is placed in <I>errbuf</I>. The length of the\r
169 message, including the zero, is limited to <I>errbuf_size</I>. The yield of the\r
170 function is the size of buffer needed to hold the whole message.\r
171 </P>\r
172 <LI><A NAME="SEC7" HREF="#TOC1">STORAGE</A>\r
173 <P>\r
174 Compiling a regular expression causes memory to be allocated and associated\r
175 with the <I>preg</I> structure. The function <B>regfree()</B> frees all such\r
176 memory, after which <I>preg</I> may no longer be used as a compiled expression.\r
177 </P>\r
178 <LI><A NAME="SEC8" HREF="#TOC1">AUTHOR</A>\r
179 <P>\r
180 Philip Hazel &#60;ph10@cam.ac.uk&#62;\r
181 <BR>\r
182 University Computing Service,\r
183 <BR>\r
184 New Museums Site,\r
185 <BR>\r
186 Cambridge CB2 3QG, England.\r
187 <BR>\r
188 Phone: +44 1223 334714\r
189 </P>\r
190 <P>\r
191 Copyright (c) 1997-2000 University of Cambridge.\r