⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regex.3.html

📁 regex-spencer-3.8-doc.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- manual page source format generated by PolyglotMan v3.0.9, -->
<!-- available via anonymous ftp from ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z -->

<HTML>
<HEAD>
<TITLE>REGEX(3) manual page</TITLE>
</HEAD>
<BODY bgcolor=white>
<A HREF="#toc">Table of Contents</A><P>
 
<H2><A NAME="sect0" HREF="#toc0">Name</A></H2>
regcomp, regexec, regerror, regfree - regular-expression library 
<H2><A NAME="sect1" HREF="#toc1">Synopsis</A></H2>
<B>
#include &lt;sys/types.h&gt; <BR>
#include &lt;regex.h&gt; 
<DL>

<DT>int regcomp(regex_t&nbsp;*preg, const&nbsp;char&nbsp;*pattern, int&nbsp;cflags);
</DT>
<DD></DD>

<DT>int&nbsp;regexec(const&nbsp;regex_t&nbsp;*preg, const&nbsp;char&nbsp;*string, </DT>
<DD>size_t&nbsp;nmatch, regmatch_t&nbsp;pmatch[],
int&nbsp;eflags); </DD>

<DT>size_t&nbsp;regerror(int&nbsp;errcode, const&nbsp;regex_t&nbsp;*preg, </DT>
<DD>char&nbsp;*errbuf,
size_t&nbsp;errbuf_size); </DD>

<DT>void&nbsp;regfree(regex_t&nbsp;*preg); </DT>
<DD> </DD>
</DL>

<H2><A NAME="sect2" HREF="#toc2"></B>Description</A></H2>
These routines
implement POSIX 1003.2 regular expressions (``RE''s); see  <I><A HREF="regex.7.html">regex</I>(7)<I></A>
.</I>  <I>Regcomp</I>
compiles an RE written as a string into an internal form, <I>regexec</I> matches
that internal form against a string and reports results, <I>regerror</I> transforms
error codes from either into human-readable messages, and <I>regfree</I> frees
any dynamically-allocated storage used by the internal form of an RE. <P>
The
header <I>&lt;regex.h&gt;</I> declares two structure types, <I>regex_t</I> and <I>regmatch_t</I>, the
former for compiled internal forms and the latter for match reporting. It
also declares the four functions, a type <I>regoff_t</I>, and a number of constants
with names starting with ``REG_''. <P>
<I>Regcomp</I> compiles the regular expression contained
in the <I>pattern</I> string, subject to the flags in <I>cflags</I>, and places the results
in the <I>regex_t</I> structure pointed to by <I>preg</I>. <I>Cflags</I> is the bitwise OR of
zero or more of the following flags: 
<DL>

<DT>REG_EXTENDED</DT>
<DD>Compile modern (``extended'')
REs, rather than the obsolete (``basic'') REs that are the default. </DD>

<DT>REG_BASIC</DT>
<DD>This
is a synonym for 0, provided as a counterpart to REG_EXTENDED to improve
readability. This is an extension, compatible with but not specified by
POSIX 1003.2, and should be used with caution in software intended to be
portable to other systems. </DD>

<DT>REG_NOSPEC</DT>
<DD>Compile with recognition of all special
characters turned off. All characters are thus considered ordinary, so the
``RE'' is a literal string. This is an extension, compatible with but not specified
by POSIX 1003.2, and should be used with caution in software intended to
be portable to other systems. REG_EXTENDED and REG_NOSPEC may not be used
in the same call to <I>regcomp</I>. </DD>

<DT>REG_ICASE</DT>
<DD>Compile for matching that ignores
upper/lower case distinctions. See  <I><A HREF="regex.7.html">regex</I>(7)<I></A>
.</I>  </DD>

<DT>REG_NOSUB</DT>
<DD>Compile for matching
that need only report success or failure, not what was matched. </DD>

<DT>REG_NEWLINE</DT>
<DD>Compile
for newline-sensitive matching. By default, newline is a completely ordinary
character with no special meaning in either REs or strings. With this flag,
`[^' bracket expressions and `.' never match newline, a `^' anchor matches the null
string after any newline in the string in addition to its normal function,
and the `$' anchor matches the null string before any newline in the string
in addition to its normal function. </DD>

<DT>REG_PEND</DT>
<DD>The regular expression ends,
not at the first NUL, but just before the character pointed to by the <I>re_endp</I>
member of the structure pointed to by <I>preg</I>. The <I>re_endp</I> member is of type
<I>const&nbsp;char&nbsp;*</I>. This flag permits inclusion of NULs in the RE; they are considered
ordinary characters. This is an extension, compatible with but not specified
by POSIX 1003.2, and should be used with caution in software intended to
be portable to other systems. </DD>
</DL>
<P>
When successful, <I>regcomp</I> returns 0 and fills
in the structure pointed to by <I>preg</I>. One member of that structure (other
than <I>re_endp</I>) is publicized: <I>re_nsub</I>, of type <I>size_t</I>, contains the number
of parenthesized subexpressions within the RE (except that the value of
this member is undefined if the REG_NOSUB flag was used). If <I>regcomp</I> fails,
it returns a non-zero error code; see DIAGNOSTICS. <P>
<I>Regexec</I> matches the compiled
RE pointed to by <I>preg</I> against the <I>string</I>, subject to the flags in <I>eflags</I>,
and reports results using <I>nmatch</I>, <I>pmatch</I>, and the returned value. The RE
must have been compiled by a previous invocation of <I>regcomp</I>. The compiled
form is not altered during execution of <I>regexec</I>, so a single compiled RE
can be used simultaneously by multiple threads. <P>
By default, the NUL-terminated
string pointed to by <I>string</I> is considered to be the text of an entire line,
with the NUL indicating the end of the line. (That is, any other end-of-line
marker is considered to have been removed and replaced by the NUL.) The
<I>eflags</I> argument is the bitwise OR of zero or more of the following flags:

<DL>

<DT>REG_NOTBOL</DT>
<DD>The first character of the string is not the beginning of a line,
so the `^' anchor should not match before it. This does not affect the behavior
of newlines under REG_NEWLINE. </DD>

<DT>REG_NOTEOL</DT>
<DD>The NUL terminating the string
does not end a line, so the `$' anchor should not match before it. This does
not affect the behavior of newlines under REG_NEWLINE. </DD>

<DT>REG_STARTEND</DT>
<DD>The string
is considered to start at <I>string</I>&nbsp;+ <I>pmatch</I>[0].<I>rm_so</I> and to have a terminating
NUL located at <I>string</I>&nbsp;+ <I>pmatch</I>[0].<I>rm_eo</I> (there need not actually be a NUL
at that location), regardless of the value of <I>nmatch</I>. See below for the
definition of <I>pmatch</I> and <I>nmatch</I>. This is an extension, compatible with but
not specified by POSIX 1003.2, and should be used with caution in software
intended to be portable to other systems. Note that a non-zero <I>rm_so</I> does
not imply REG_NOTBOL; REG_STARTEND affects only the location of the string,
not how it is matched. </DD>
</DL>
<P>
See  <I><A HREF="regex.7.html">regex</I>(7)<I></I></A>
  for a discussion of what is matched
in situations where an RE or a portion thereof could match any of several
substrings of <I>string</I>. <P>
Normally, <I>regexec</I> returns 0 for success and the non-zero
code REG_NOMATCH for failure. Other non-zero error codes may be returned
in exceptional situations; see DIAGNOSTICS. <P>
If REG_NOSUB was specified in
the compilation of the RE, or if <I>nmatch</I> is 0, <I>regexec</I> ignores the <I>pmatch</I>
argument (but see below for the case where REG_STARTEND is specified). Otherwise,
<I>pmatch</I> points to an array of <I>nmatch</I> structures of type <I>regmatch_t</I>. Such
a structure has at least the members <I>rm_so</I> and <I>rm_eo</I>, both of type <I>regoff_t</I>
(a signed arithmetic type at least as large as an <I>off_t</I> and a <I>ssize_t</I>),
containing respectively the offset of the first character of a substring
and the offset of the first character after the end of the substring. Offsets
are measured from the beginning of the <I>string</I> argument given to <I>regexec</I>.
An empty substring is denoted by equal offsets, both indicating the character
following the empty substring. <P>
The 0th member of the <I>pmatch</I> array is filled
in to indicate what substring of <I>string</I> was matched by the entire RE. Remaining
members report what substring was matched by parenthesized subexpressions

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -