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