📄 pcreposix.3
字号:
.TH PCRE 3.SH NAMEpcreposix - POSIX API for Perl-compatible regular expressions..SH SYNOPSIS.B #include <pcreposix.h>.PP.SM.br.B int regcomp(regex_t *\fIpreg\fR, const char *\fIpattern\fR,.ti +5n.B int \fIcflags\fR);.PP.br.B int regexec(regex_t *\fIpreg\fR, const char *\fIstring\fR,.ti +5n.B size_t \fInmatch\fR, regmatch_t \fIpmatch\fR[], int \fIeflags\fR);.PP.br.B size_t regerror(int \fIerrcode\fR, const regex_t *\fIpreg\fR,.ti +5n.B char *\fIerrbuf\fR, size_t \fIerrbuf_size\fR);.PP.br.B void regfree(regex_t *\fIpreg\fR);.SH DESCRIPTIONThis set of functions provides a POSIX-style API to the PCRE regular expressionpackage. See the \fBpcre\fR documentation for a description of the native API,which contains additional functionality.The functions described here are just wrapper functions that ultimately callthe native API. Their prototypes are defined in the \fBpcreposix.h\fR headerfile, and on Unix systems the library itself is called \fBpcreposix.a\fR, socan be accessed by adding \fB-lpcreposix\fR to the command for linking anapplication which uses them. Because the POSIX functions call the native ones,it is also necessary to add \fR-lpcre\fR.I have implemented only those option bits that can be reasonably mapped to PCREnative options. In addition, the options REG_EXTENDED and REG_NOSUB are definedwith the value zero. They have no effect, but since programs that are writtento the POSIX interface often use them, this makes it easier to slot in PCRE asa replacement library. Other POSIX options are not even defined.When PCRE is called via these functions, it is only the API that is POSIX-likein style. The syntax and semantics of the regular expressions themselves arestill those of Perl, subject to the setting of various PCRE options, asdescribed below.The header for these functions is supplied as \fBpcreposix.h\fR to avoid anypotential clash with other POSIX libraries. It can, of course, be renamed oraliased as \fBregex.h\fR, which is the "correct" name. It provides twostructure types, \fIregex_t\fR for compiled internal forms, and\fIregmatch_t\fR for returning captured substrings. It also defines someconstants whose names start with "REG_"; these are used for setting options andidentifying error codes..SH COMPILING A PATTERNThe function \fBregcomp()\fR is called to compile a pattern into aninternal form. The pattern is a C string terminated by a binary zero, andis passed in the argument \fIpattern\fR. The \fIpreg\fR argument is a pointerto a regex_t structure which is used as a base for storing information aboutthe compiled expression.The argument \fIcflags\fR is either zero, or contains one or more of the bitsdefined by the following macros: REG_ICASEThe PCRE_CASELESS option is set when the expression is passed for compilationto the native function. REG_NEWLINEThe PCRE_MULTILINE option is set when the expression is passed for compilationto the native function.The yield of \fBregcomp()\fR is zero on success, and non-zero otherwise. The\fIpreg\fR structure is filled in on success, and one member of the structureis publicized: \fIre_nsub\fR contains the number of capturing subpatterns inthe regular expression. Various error codes are defined in the header file..SH MATCHING A PATTERNThe function \fBregexec()\fR is called to match a pre-compiled pattern\fIpreg\fR against a given \fIstring\fR, which is terminated by a zero byte,subject to the options in \fIeflags\fR. These can be: REG_NOTBOLThe PCRE_NOTBOL option is set when calling the underlying PCRE matchingfunction. REG_NOTEOLThe PCRE_NOTEOL option is set when calling the underlying PCRE matchingfunction.The portion of the string that was matched, and also any captured substrings,are returned via the \fIpmatch\fR argument, which points to an array of\fInmatch\fR structures of type \fIregmatch_t\fR, containing the members\fIrm_so\fR and \fIrm_eo\fR. These contain the offset to the first character ofeach substring and the offset to the first character after the end of eachsubstring, respectively. The 0th element of the vector relates to the entireportion of \fIstring\fR that was matched; subsequent elements relate to thecapturing subpatterns of the regular expression. Unused entries in the arrayhave both structure members set to -1.A successful match yields a zero return; various error codes are defined in theheader file, of which REG_NOMATCH is the "expected" failure code..SH ERROR MESSAGESThe \fBregerror()\fR function maps a non-zero errorcode from either\fBregcomp\fR or \fBregexec\fR to a printable message. If \fIpreg\fR is notNULL, the error should have arisen from the use of that structure. A messageterminated by a binary zero is placed in \fIerrbuf\fR. The length of themessage, including the zero, is limited to \fIerrbuf_size\fR. The yield of thefunction is the size of buffer needed to hold the whole message..SH STORAGECompiling a regular expression causes memory to be allocated and associatedwith the \fIpreg\fR structure. The function \fBregfree()\fR frees all suchmemory, after which \fIpreg\fR may no longer be used as a compiled expression..SH AUTHORPhilip Hazel <ph10@cam.ac.uk>.brUniversity Computing Service,.brNew Museums Site,.brCambridge CB2 3QG, England..brPhone: +44 1223 334714Copyright (c) 1997-1999 University of Cambridge.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -