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

📄 regfree.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>regcomp</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_008_066">&nbsp;</a>NAME</h4><blockquote>regcomp, regexec, regerror, regfree - regular expression matching</blockquote><h4><a name = "tag_000_008_067">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="systypes.h.html">sys/types.h</a>&gt;#include &lt;<a href="regex.h.html">regex.h</a>&gt;int regcomp(regex_t *<i>preg</i>, const char *<i>pattern</i>, int <i>cflags</i>);int regexec(const regex_t *<i>preg</i>, const char *<i>string</i>,    size_t <i>nmatch</i>, regmatch_t <i>pmatch</i>[], int <i>eflags</i>);size_t regerror(int <i>errcode</i>, const regex_t *<i>preg</i>,    char *<i>errbuf</i>, size_t <i>errbuf_size</i>);void regfree(regex_t *<i>preg</i>);</code></pre></blockquote><h4><a name = "tag_000_008_068">&nbsp;</a>DESCRIPTION</h4><blockquote>These functions interpret<i>basic</i>and<i>extended</i>regular expressions as described in the <b>XBD</b> specification, <a href="../xbd/re.html"><b>Regular Expressions</b>&nbsp;</a>.<p>The structure type<b>regex_t</b>contains at least the following member:<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Member Type</b><th align=center><b>Member Name</b><th align=center><b>Description</b><tr valign=top><td align=left>size_t<td align=left>re_nsub<td align=left>Number of parenthesised subexpressions.</table><p>The structure type<b>regmatch_t</b>contains at least the following members:<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Member Type</b><th align=center><b>Member Name</b><th align=center><b>Description</b><tr valign=top><td align=left>regoff_t<td align=left>rm_so<td align=left>Byte offset from start of <i>string</i> to start of substring.<tr valign=top><td align=left>regoff_t<td align=left>rm_eo<td align=left> Byte offset from start of <i>string</i> of the first character after the end of substring. </table><p>The<i>regcomp()</i>function will compile the regular expression contained in the string pointedto by the<i>pattern</i>argument and place the results in the structure pointed to by<i>preg.</i>The<i>cflags</i>argument is the bitwise inclusive OR of zero or more ofthe following flags, which are defined in the header<i><a href="regex.h.html">&lt;regex.h&gt;</a></i>:<dl compact><dt>REG_EXTENDED<dd>Use Extended Regular Expressions.<dt>REG_ICASE<dd>Ignore case in match.  (See the <b>XBD</b> specification, <a href="../xbd/re.html"><b>Regular Expressions</b>&nbsp;</a>.)<dt>REG_NOSUB<dd>Report only success/fail in<i>regexec()</i>.<dt>REG_NEWLINE<dd>Change the handling of newline characters, as described in the text.</dl><p>The default regular expression type for<i>pattern</i>is a Basic Regular Expression.The application can specify Extended Regular Expressions using theREG_EXTENDED<i>cflags</i>flag.<p>On successful completion,it returns 0; otherwise it returns non-zero, and the content of<i>preg</i>is undefined.<p>If the REG_NOSUB flag was not set in<i>cflags</i>,then<i>regcomp()</i>will set<i>re_nsub</i>to the number of parenthesised subexpressions (delimited by \( \)in basic regular expressions or ( ) in extendedregular expressions) found in<i>pattern.</i><p>The<i>regexec()</i>function compares the null-terminated string specified by<i>string</i>with the compiled regular expression<i>preg</i>initialised by a previous call to<i>regcomp()</i>.If it finds a match,<i>regexec()</i>returns 0; otherwise it returns non-zero indicating either no match or anerror.  The<i>eflags</i>argument is the bitwise inclusive OR of zero or more of the following flags,which are defined in the header<i><a href="regex.h.html">&lt;regex.h&gt;</a></i>:<dl compact><dt>REG_NOTBOL<dd>The first character of the string pointed to by<i>string</i>is not the beginning of the line.  Therefore, the circumflex character(^), when taken as a special character, will not match the beginning of<i>string</i>.<dt>REG_NOTEOL<dd>The last character of the string pointed to by<i>string</i>is not the end of the line.  Therefore, the dollar sign ($), when takenas a special character, will not match the end of<i>string</i>.</dl><p>If<i>nmatch</i>is 0 or REG_NOSUB was set in the<i>cflags</i>argument to<i>regcomp()</i>,then<i>regexec()</i>will ignore the<i>pmatch</i>argument.Otherwise, the<i>pmatch</i>argument must point to an array with at least<i>nmatch</i>elements, and<i>regexec()</i>will fill in the elements of thatarray with offsets of the substrings of<i>string</i>that correspond to the parenthesised subexpressions of<i>pattern</i>:<i>pmatch</i>[<i>i</i>].<i>rm_so</i>will be the byte offset of the beginning and<i>pmatch</i>[<i>i</i>].<i>rm_eo</i>will be one greater than the byte offset of theend of substring<i>i</i>.(Subexpression<i>i</i>begins at the<i>i</i>thmatched open parenthesis, counting from 1.)Offsets in<i>pmatch</i>[0]identify the substring that corresponds to the entire regular expression.Unused elements of<i>pmatch</i>up to<i>pmatch</i>[<i>nmatch</i>-1]will be filled with -1.If there are more than<i>nmatch</i>subexpressions in<i>pattern</i>(<i>pattern</i>itself counts as a subexpression), then<i>regexec()</i>will still do the match, but will record only the first<i>nmatch</i>substrings.<p>When matching a basic or extended regular expression, any given parenthesisedsubexpression of<i>pattern</i>might participate in the match of several different substrings of<i>string</i>,or it might not match any substring even though the pattern as a wholedid match.The following rules are used to determine which substrings toreport in<i>pmatch</i>when matchingregular expressions:<ol><p><li>If subexpression<i>i</i>in a regular expression is not contained within another subexpression, and itparticipated in the match several times, then the byte offsets in<i>pmatch</i>[<i>i</i>]will delimit the last such match.<p><li>If subexpression<i>i</i>is not contained within another subexpression, and itdid not participate in an otherwise successful match, the byte offsets in<i>pmatch</i>[<i>i</i>]will be -1.  A subexpression does not participate in the match when:<p><dl compact><dt> <dd>* or \{ \} appears immediately after the subexpression in a basic regularexpression, or *, ?, or { } appears immediately after the subexpression inan extended regular expression, and the subexpression did not match(matched 0 times)</dl><p>or:<dl compact><dt> <dd>| is used in an extended regular expression to select this subexpression oranother, and the other subexpression matched.</dl><p><li>If subexpression<i>i</i>is contained within another subexpression<i>j</i>,and<i>i</i>is not contained within any other subexpression that is contained within<i>j</i>,and a match of subexpression<i>j</i>is reported in<i>pmatch</i>[<i>j</i>],then the match or non-match of subexpression<i>i</i>reported in<i>pmatch</i>[<i>i</i>]will be as described in 1. and 2. above, but within the substring reported in<i>pmatch</i>[<i>j</i>]rather than the whole string.<br><p><li>If subexpression<i>i</i>is contained in subexpression<i>j</i>,and the byte offsets in<i>pmatch</i>[<i>j</i>]are -1, then the pointers in<i>pmatch</i>[<i>i</i>]also will be -1.<br><p><li>If subexpression<i>i</i>matched a zero-length string, then both byte offsets in<i>pmatch</i>[<i>i</i>]will be the byte offset of the characteror null terminator immediately followingthe zero-length string.<p></ol><p>

⌨️ 快捷键说明

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