📄 regexp.html
字号:
(Concatenation.)<dt><i>r</i>\{<i>m</i>,<i>n</i>\}<dd>Any number of<i>m</i>through<i>n</i>successive occurrences of the regular expression<i>r</i>.The regular expression<i>r</i>\{<i>m</i>\}matches exactly<i>m</i>occurrences,<i>r</i>\{<i>m</i>,\}matches at least<i>m</i>occurrences. The maximum number of occurrences is matched.<dt>\(<i>r</i>\)<dd>The regular expression<i>r</i>.The<i>\(</i>and<i>\)</i>sequences are ignored.<dt>\<i>n</i><dd>When<i>\n</i>(where<i>n</i>is a number in the range 1 to 9) appears in a concatenatedregular expression, it stands for the regular expression<i>x</i>,where<i>x</i>is the<i>n</i>thregular expression enclosed in \( and \)sequences that appearedearlier in the concatenated regular expression.For example, in the pattern<i>\(r\)x\(y</i>the<i>\2</i>matches the regular expression<i>y</i>,giving<i>rxyzy</i>.</dl><p>Characters that have special meaning except where they appear withinsquare brackets, [] , or are preceded by "\" are:<pre><code></code></pre>Other special characters, such as $ have special meaning in morerestricted contexts.<p>The character "^"at the beginning of an expression permits a successfulmatch only immediately after a newline or at the beginning ofeach of the strings to which the match is applied, and the character"$" at the end of an expression requires a trailing newline.<p>Two characters have special meaning only when used within squarebrackets.The character "-" denotes a range, [<i>c</i> - <i>c</i> ],unless it is just after the left square bracket or before theright square bracket, [-<i>c</i> ]or [<i>c</i> -],in which case it has no special meaning.The character "^" has the meaning<i>complement of</i>if it immediately follows the left square bracket, [^<i>c</i> ].Elsewhere between brackets, [<i>c</i>^],it stands for the ordinary character "^".The right square bracket (]) loses its special meaning andrepresents itself in a bracket expression if it occurs first inthe list after any initial circumflex (^) character.<p>The special meaning of the "\" operator can be escaped<i>only</i>by preceding it with another "\"; that is, "\\".<br><h5><a name = "tag_000_008_059_003"> </a>SRE Operator Precedence</h5>The precedence of the operators is as shown below:<dl compact><dt>[...]<dd>High precedence.<dt>*<dd><dt>concatenation<dd>Low precedence.</dl><h5><a name = "tag_000_008_059_004"> </a>Internationalised SREs</h5>Character expressions within square brackets are constructed asfollows:<dl compact><dt><b>Expression</b><dd><b>Meaning</b><dt><i>c</i><dd>The single character<i>c</i>where<i>c</i>is not a special character.<dt>[[:<i>class</i>:]]<dd>A character class expression. Any character of type<i>class</i>,as defined by category LC_CTYPEin the program's locale (see the <b>XBD</b> specification, <a href="../xbd/locale.html"><b>Locale</b> </a>).For<i>class</i>,one of the following should be substituted:<dl compact><dt>alpha<dd>A letter.<dt>upper<dd>An upper-case letter.<dt>lower<dd>A lower-case letter.<dt>digit<dd>A decimal digit.<dt>xdigit<dd>A hexadecimal digit.<dt>alnum<dd>An alphanumeric (letter or digit).<dt>space<dd>A character producing white space in displayed text.<dt>punct<dd>A punctuation character.<dt>print<dd>A printing character.<dt>graph<dd>A character with a visible representation.<dt>cntrl<dd>A control character.</dl><p><dt>[[<i>=c=</i>]]<dd>An equivalence class. Any collation element defined as having the samerelative order in the current collation sequence as<i>c</i>.As an example, if<b>A</b>and<b>a</b>belong to the same equivalence class, then both [[<i>=A=</i>]<i>b</i>]and [[<i>=a=</i>]<i>b</i>]are equivalent to [<i>Aab</i>].<br><p><dt>[[<i>.cc.</i>]]<dd>A collating symbol. Multi-character collating elements must berepresented as collating symbols to distinguish them fromsingle-character collating elements. As an example, if the string<i>ch</i>is a valid collating element, then [[<i>.ch.</i>]]will be treated as an element matching the same stringof characters, while<i>ch</i>will be treated as a simple list of<i>c</i>and<i>h</i>.If the string is not a valid collating element in the currentcollating sequence definition, the symbol will be treated as aninvalid expression.<p><dt>[<i>c-c</i>]<dd>Any collation element in the character expression range<i>c-c</i>,where<i>c</i>can identify a collating symbol or an equivalence class.If the character "-" appears immediately after an openingsquare bracket (for example, [-<i>c</i>]) or immediately prior toa closing square bracket (for example, [<i>c</i>-]), it has nospecial meaning.<p><dt>^<dd>Immediately following an opening squarebracket, means the complement of, for example, [^<i>c</i>].Otherwise, it has no special meaning.<p></dl><p>Within square brackets, a "." that is not part of a [[<i>.cc.</i>]]sequence, or a ":" that is not part of a [[:<i>class</i>:]]sequence, or an "=" that is not part of a [[<i>=c=</i>]]sequence, matches itself.<br><h5><a name = "tag_000_008_059_005"> </a>SRE Examples</h5>Below are examples of regular expressions:<p><table bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Pattern</b><th align=center><b>Meaning</b><tr valign=top><td align=left>ab.d<td align=left>ab <i>any character</i> d<tr valign=top><td align=left>ab.*d<td align=left>ab <i>any sequence of characters (including none)</i> d<tr valign=top><td align=left>ab[xyz]d<td align=left>ab <i>one of </i>x y <i>or</i> z d<tr valign=top><td align=left>ab[c]d<td align=left>ab <i>anything except </i>c d<tr valign=top><td align=left>abcd$<td align=left><i>a line containing only</i> abcd<tr valign=top><td align=left>[a-d]<td align=left><i>any one of</i> a b c <i>or</i> d</table><p>These interfaces need not be reentrant.</blockquote><h4><a name = "tag_000_008_060"> </a>RETURN VALUE</h4><blockquote>The<i><a href="compile.html">compile()</a></i>function uses the macro RETURN() on success and the macro ERROR()on failure, see above.The<i><a href="step.html">step()</a></i>and<i><a href="advance.html">advance()</a></i>functions return non-zero on a successful match and 0 if there is no match.</blockquote><h4><a name = "tag_000_008_061"> </a>ERRORS</h4><blockquote><dl compact><dt>11<dd>Range endpoint too large.<dt>16<dd>Bad number.<dt>25<dd>\digit out of range.<dt>36<dd>Illegal or missing delimiter.<dt>41<dd>No remembered search string.<dt>42<dd>\( \) imbalance.<dt>43<dd>Too many \( .<dt>44<dd>More than two numbers given in \{ \} .<dt>45<dd>} expected after \ .<dt>46<dd>First number exceeds second in \{ \} .<dt>49<dd>[ ] imbalance.<dt>50<dd>Regular expression overflow.</dl></blockquote><h4><a name = "tag_000_008_062"> </a>EXAMPLES</h4><blockquote>The following is an example of how the regular expression macros andcalls might be defined by an application program:<pre><code>#define INIT char *sp = instring;#define GETC() (*sp++)#define PEEKC() (*sp)#define UNGETC(c) (--sp)#define RETURN(c) return;#define ERROR(c) regerr()#include <regexp.h> (void) compile(*argv, expbuf, &expbuf[ESIZE], \0); if (step(linebuf, expbuf) ) succeed();</code></pre></blockquote><h4><a name = "tag_000_008_063"> </a>APPLICATION USAGE</h4><blockquote>Applications should migrate to the<i><a href="fnmatch.html">fnmatch()</a></i>,<i><a href="glob.html">glob()</a></i>,<i><a href="regcomp.html">regcomp()</a></i>and<i><a href="regexec.html">regexec()</a></i>functions which provide full internationalised regular expressionfunctionality compatible with the ISO POSIX-2 standard, as described in the <b>XBD</b> specification, <a href="../xbd/re.html"><b>Regular Expressions</b> </a>.</blockquote><h4><a name = "tag_000_008_064"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_065"> </a>SEE ALSO</h4><blockquote><i><a href="fnmatch.html">fnmatch()</a></i>,<i><a href="glob.html">glob()</a></i>,<i><a href="regcomp.html">regcomp()</a></i>,<i><a href="regexec.html">regexec()</a></i>,<i><a href="setlocale.html">setlocale()</a></i>,<i><a href="regex.h.html"><regex.h></a></i>,<i><a href="regexp.h.html"><regexp.h></a></i>,the <b>XBD</b> specification, <a href="../xbd/re.html"><b>Regular Expressions</b> </a>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from Issue 2 of the SVID.</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 + -