📄 re_exec.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>re_comp</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_007_1888"> </a>NAME</h4><blockquote>re_comp, re_exec - compile and execute regular expressions(<b>LEGACY</b>)</blockquote><h4><a name = "tag_000_007_1889"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="re_comp.h.html">re_comp.h</a>>char *re_comp(const char *<i>string</i>);int re_exec(const char *<i>string</i>);</code></pre></blockquote><h4><a name = "tag_000_007_1890"> </a>DESCRIPTION</h4><blockquote>The<i>re_comp()</i>function converts a regular expression string (RE) into an internal formsuitable for pattern matching. The<i>re_exec()</i>function compares the string pointed to by the <i>string</i> argument with thelast regular expression passed to<i>re_comp()</i>.<p>If<i>re_comp()</i>is called with a null pointer argument, the current regular expression remainsunchanged.<p>Strings passed to both<i>re_comp()</i>and<i>re_exec()</i>must be terminated by a null byte, and may include newline characters.<p>The<i>re_comp()</i>and<i>re_exec()</i>functions support<i>simple regular expressions</i>,which are defined below.<p>The following one-character REs match a single character:<dl compact><dt>1.1<dd>An ordinary character (not one of those discussed in 1.2 below) is aone-character RE that matches itself.<dt>1.2<dd>A backslash (\) followed by any special character is a one-character RE thatmatches the special character itself. The special characters are:<ol type = a><li><b>.</b>, <b>*</b>, <b>[</b>, and<b>\</b> (period, asterisk, left square bracket,and backslash, respectively), which are always special, exceptwhen they appear within square brackets (<b>[]</b>; see 1.4 below).<li>^ (caret or circumflex), which is special at thebeginning of an entire RE (see 3.1 and 3.2 below), or when it immediatelyfollows the left of a pair of square brackets (<b>[]</b>) (see 1.4below).<li><b>$</b> (dollar symbol), which is special at the end of an entire RE (see3.2 below).<li>The character used to bound (delimit) an entire RE, which is special for thatRE.</ol><dt>1.3<dd>A period (<b>.</b>) is a one-character RE that matches any character exceptnew-line.<dt>1.4<dd>A non-empty string of characters enclosed in square brackets (<b>[]</b>)is a one-character RE that matches any onecharacter in that string.If, however, the first character of the string is a circumflex(^), the one-character RE matches any character exceptnew-line and the remaining characters in the string.The ^ has this special meaning only if it occurs first in the string.The minus (<b>-</b>) may be used to indicate a range of consecutiveASCII characters;for example, <b>[0-9]</b> is equivalent to <b>[0123456789]</b>.The <b>-</b> loses this special meaning if it occurs first (afteran initial ^, if any) or last in the string.The right square bracket (<b>]</b>) does not terminate such a string when itis the first character within it (after an initial ^, if any);for example, <b>[]a-f]</b> matches either a right squarebracket (<b>]</b>) or one of the letters <b>a</b> through <b>f</b> inclusive.The four characters listed in 1.2.a above stand for themselveswithin such a string of characters.</dl><br><p>The following rules may be used to construct REs from one-character REs:<dl compact><dt>2.1<dd>A one-character RE is a RE that matches whatever the one-character RE matches.<dt>2.2<dd>A one-character RE followed by an asterisk (<b>*</b>) is a RE that matcheszero or more occurrences of the one-character RE. If there is any choice, thelongest leftmost string that permits a match is chosen.<dt>2.3<dd>A one-character REfollowed by <b>\{</b><i>m</i><b>\}</b>,<b>\{</b><i>m,</i><b>\}</b>, or<b>\{</b><i>m,n</i><b>\}</b> is aRE that matches arange of occurrences of the one-character RE. The values of<i>m</i>and<i>n</i>must be non-negative integers less than 256;<b>\{</b><i>m</i><b>\}</b> matchesexactly<i>m</i>occurrences;<b>\{</b><i>m,</i><b>\}</b> matchesat least<i>m</i>occurrences;<b>\{</b><i>m,n</i><b>\}</b> matchesany numberof occurrencesbetween<i>m</i>and<i>n</i>inclusive. Whenever a choice exists, the RE matches as many occurrences aspossible.<dt>2.4<dd>The concatenation of REs is a RE that matches the concatenation of the stringsmatched by each component of the RE.<dt>2.5<dd>A RE enclosed between the character sequences <b>\(</b> and <b>\)</b> is aRE that matches whatever the unadorned RE matches.<dt>2.6<dd>The expression <b>\</b><i>n</i> matches the same string of charactersas was matched by an expression enclosed between <b>\(</b> and <b>\)</b>earlier in the same RE. Here<i>n</i>is a digit; the sub-expression specified is that beginning with the<i>n</i>-thoccurrence of <b>\(</b> counting from the left.For example, the expression ^\(.*\)\1$ matches a lineconsisting of two repeated appearances of the same string.</dl><p>Finally, an entireRE may be constrained to match only an initial segment or final segment of aline (or both).<dl compact><dt>3.1<dd>A circumflex (^) at the beginning of an entire RE constrains that RE to matchan initial segment of a line.<dt>3.2<dd>A dollar symbol (<b>$</b>) at the end of an entire RE constrains that REto match a finalsegment of a line. The construction ^<i>entire RE</i>$ constrains theentire RE to match the entire line.</dl><p>The null RE (that is, <b>//</b>) is equivalent to the last RE encountered.<p>The behaviour of<i>re_comp()</i>and<i>re_exec()</i>in locales other than the POSIX locale is unspecified.<p>These interfaces need not be reentrant.</blockquote><h4><a name = "tag_000_007_1891"> </a>RETURN VALUE</h4><blockquote>The<i>re_comp()</i>function returns a null pointer when the string pointed to by the <i>string</i>argument is successfully converted. Otherwise, a pointer toan unspecified error message string is returned.<p>Upon successful completion,<i>re_exec()</i>returns 1 if <i>string</i>matches the last compiled regular expression. Otherwise,<i>re_exec()</i>returns 0 if <i>string</i> fails to match the lastcompiled regular expression, and -1 if the compiled regularexpression is invalid (indicating an internal error).</blockquote><h4><a name = "tag_000_007_1892"> </a>ERRORS</h4><blockquote>No errors are defined.</blockquote><h4><a name = "tag_000_007_1893"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1894"> </a>APPLICATION USAGE</h4><blockquote>For portability to implementations conforming to earlier versions of thisspecification,<i><a href="regcomp.html">regcomp()</a></i>and<i><a href="regexec.html">regexec()</a></i>are preferred to these functions.</blockquote><h4><a name = "tag_000_007_1895"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1896"> </a>SEE ALSO</h4><blockquote><i><a href="regcomp.html">regcomp()</a></i>,<i><a href="re_comp.h.html"><re_comp.h></a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -