📄 xbd_chap09.html
字号:
<dd>In a BRE, one of the character sequences: <blockquote><pre><tt>\^ \. \* \[ \$ \\</tt></pre></blockquote><p>In an ERE, one of the character sequences:</p><blockquote><pre><tt>\^ \. \[ \$ \( \) \|\* \+ \? \{ \\</tt></pre></blockquote></dd><dt><b>R_ANCHOR</b></dt><dd>(Applicable only to basic regular expressions.) The character <tt>'$'</tt> when it appears as the last character of a basicregular expression and when not <b>QUOTED_CHAR</b>. The <tt>'$'</tt> may be recognized as an anchor elsewhere; see <a href="#tag_09_03_08">BRE Expression Anchoring</a> .</dd><dt><b>SPEC_CHAR</b></dt><dd>For basic regular expressions, one of the following special characters: <dl compact><dt><tt>.</tt></dt><dd>Anywhere outside bracket expressions</dd><dt><tt>\</tt></dt><dd>Anywhere outside bracket expressions</dd><dt><tt>[</tt></dt><dd>Anywhere outside bracket expressions</dd><dt><tt>^</tt></dt><dd>When used as an anchor (see <a href="#tag_09_03_08">BRE Expression Anchoring</a> ) or when first in a bracket expression</dd><dt><tt>$</tt></dt><dd>When used as an anchor</dd><dt><tt>*</tt></dt><dd>Anywhere except first in an entire RE, anywhere in a bracket expression, directly following <tt>"\("</tt> , directly followingan anchoring <tt>'^'</tt></dd></dl><p>For extended regular expressions, shall be one of the following special characters found anywhere outside bracketexpressions:</p><blockquote><pre><tt>^ . [ $ ( ) |* + ? { \</tt></pre></blockquote><p>(The close-parenthesis shall be considered special in this context only if matched with a preceding open-parenthesis.)</p></dd></dl><h4><a name="tag_09_05_02"></a>RE and Bracket Expression Grammar</h4><p>This section presents the grammar for basic regular expressions, including the bracket expression grammar that is common to bothBREs and EREs.</p><pre><tt>%token ORD_CHAR QUOTED_CHAR DUP_COUNT<br>%token BACKREF L_ANCHOR R_ANCHOR<br>%token Back_open_paren Back_close_paren/* '\(' '\)' */<br>%token Back_open_brace Back_close_brace/* '\{' '\}' */<br>/* The following tokens are for the Bracket Expression grammar common to both REs and EREs. */<br>%token COLL_ELEM_SINGLE COLL_ELEM_MULTI META_CHAR<br>%token Open_equal Equal_close Open_dot Dot_close Open_colon Colon_close/* '[=' '=]' '[.' '.]' '[:' ':]' */<br>%token class_name/* class_name is a keyword to the LC_CTYPE locale category *//* (representing a character class) in the current locale *//* and is only recognized between [: and :] */<br>%start basic_reg_exp%%<br>/* -------------------------------------------- Basic Regular Expression --------------------------------------------*/basic_reg_exp : RE_expression | L_ANCHOR | R_ANCHOR | L_ANCHOR R_ANCHOR | L_ANCHOR RE_expression | RE_expression R_ANCHOR | L_ANCHOR RE_expression R_ANCHOR ;RE_expression : simple_RE | RE_expression simple_RE ;simple_RE : nondupl_RE | nondupl_RE RE_dupl_symbol ;nondupl_RE : one_char_or_coll_elem_RE | Back_open_paren RE_expression Back_close_paren | BACKREF ;one_char_or_coll_elem_RE : ORD_CHAR | QUOTED_CHAR | '.' | bracket_expression ;RE_dupl_symbol : '*' | Back_open_brace DUP_COUNT Back_close_brace | Back_open_brace DUP_COUNT ',' Back_close_brace | Back_open_brace DUP_COUNT ',' DUP_COUNT Back_close_brace ;<br>/* -------------------------------------------- Bracket Expression -------------------------------------------*/bracket_expression : '[' matching_list ']' | '[' nonmatching_list ']' ;matching_list : bracket_list ;nonmatching_list : '^' bracket_list ;bracket_list : follow_list | follow_list '-' ;follow_list : expression_term | follow_list expression_term ;expression_term : single_expression | range_expression ;single_expression : end_range | character_class | equivalence_class ;range_expression : start_range end_range | start_range '-' ;start_range : end_range '-' ;end_range : COLL_ELEM_SINGLE | collating_symbol ;collating_symbol : Open_dot COLL_ELEM_SINGLE Dot_close | Open_dot COLL_ELEM_MULTI Dot_close | Open_dot META_CHAR Dot_close ;equivalence_class : Open_equal COLL_ELEM_SINGLE Equal_close | Open_equal COLL_ELEM_MULTI Equal_close ;character_class : Open_colon class_name Colon_close ;</tt></pre><p>The BRE grammar does not permit <b>L_ANCHOR</b> or <b>R_ANCHOR</b> inside <tt>"\("</tt> and <tt>"\)"</tt> (which implies that<tt>'^'</tt> and <tt>'$'</tt> are ordinary characters). This reflects the semantic limits on the application, as noted in <a href="#tag_09_03_08">BRE Expression Anchoring</a> . Implementations are permitted to extend the language to interpret <tt>'^'</tt> and<tt>'$'</tt> as anchors in these locations, and as such, conforming applications cannot use unescaped <tt>'^'</tt> and <tt>'$'</tt>in positions inside <tt>"\("</tt> and <tt>"\)"</tt> that might be interpreted as anchors.</p><h4><a name="tag_09_05_03"></a>ERE Grammar</h4><p>This section presents the grammar for extended regular expressions, excluding the bracket expression grammar. <basefont size="2"></p><dl><dt><b>Note:</b></dt><dd>The bracket expression grammar and the associated <b>%token</b> lines are identical between BREs and EREs. It has been omittedfrom the ERE section to avoid unnecessary editorial duplication.</dd></dl><basefont size="3"> <pre><tt>%token ORD_CHAR QUOTED_CHAR DUP_COUNT%start extended_reg_exp%%<br>/* -------------------------------------------- Extended Regular Expression --------------------------------------------*/extended_reg_exp : ERE_branch | extended_reg_exp '|' ERE_branch ;ERE_branch : ERE_expression | ERE_branch ERE_expression ;ERE_expression : one_char_or_coll_elem_ERE | '^' | '$' | '(' extended_reg_exp ')' | ERE_expression ERE_dupl_symbol ;one_char_or_coll_elem_ERE : ORD_CHAR | QUOTED_CHAR | '.' | bracket_expression ;ERE_dupl_symbol : '*' | '+' | '?' | '{' DUP_COUNT '}' | '{' DUP_COUNT ',' '}' | '{' DUP_COUNT ',' DUP_COUNT '}' ;</tt></pre><p>The ERE grammar does not permit several constructs that previous sections specify as having undefined results:</p><ul><li><p><b>ORD_CHAR</b> preceded by <tt>'\'</tt></p></li><li><p>One or more <i>ERE_dupl_symbol</i>s appearing first in an ERE, or immediately following <tt>'|'</tt> , <tt>'^'</tt> , or<tt>'('</tt></p></li><li><p><tt>'{'</tt> not part of a valid <i>ERE_dupl_symbol</i></p></li><li><p><tt>'|'</tt> appearing first or last in an ERE, or immediately following <tt>'|'</tt> or <tt>'('</tt> , or immediately preceding<tt>')'</tt></p></li></ul><p>Implementations are permitted to extend the language to allow these. Conforming applications cannot use such constructs.</p><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -