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

📄 re.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
and the EREa^bis valid, but can never match because theaprevents the expression^bfrom matching starting at the first character.<p><li>A dollar sign($)outside a bracket expression anchorsthe expression or subexpression it ends tothe end of a string;such an expression or subexpression can match onlya sequence ending at the last character of a string.For example, the EREsef$and(ef$)matchefin the stringabcdef,but fail to match in the stringcdefab,and the EREe$fis valid, but can never match because thefprevents the expressione$from matching ending at the last character.<p></ol><h3><a name = "tag_007_005">&nbsp;</a>Regular Expression Grammar</h3><xref type="2" name="regram"></xref>Grammars describing the syntax of bothbasic and extended regular expressionsare presented in this section.The grammar takes precedence over the text.Seethe <b>XCU</b> specification, <b>Section 1.8</b>, <b>Grammar Conventions</b>.<h4><a name = "tag_007_005_001">&nbsp;</a>BRE/ERE Grammar Lexical Conventions</h4>The lexical conventions for regular expressionsare as described in this section.<p>Except as noted, the longest possibletoken or delimiter beginning at a given point will be recognised.<p>The following tokens will be processed (in additionto those string constants shown in the grammar):<dl compact><dt>COLL_ELEM<dd>Any single-character collating element, unless it is aMETA_CHAR.<dt>BACKREF<dd>Applicable only to basic regular expressions.The character string consisting of "\" followed by a single-digit numeral,1 to 9.<dt>DUP_COUNT<dd>Represents a numeric constant.It is an integer in the range0 &lt;=DUP_COUNT&lt;={RE_DUP_MAX}.This token will only be recognised when thecontext of the grammar requires it.At all other times, digits not preceded by "\" will be treated as ORD_CHAR.<dt>META_CHAR<dd>One of the characters:<dl compact><dt>^<dd>when found first in a bracket expression<dt>-<dd>when found anywhere but first (after an initial "^", if any)or last in a bracket expression, or as the ending range pointin a range expression<dt>]<dd>when found anywhere but first (after an initial "^" if any) ina bracket expression.</dl><p><dt>L_ANCHOR<dd>Applicable only to basic regular expressions.The character "^" when it appears as the first character ofa basic regular expression and when not QUOTED_CHAR.The "^" may be recognised as an anchor elsewhere; see<xref href=breanc><a href="#tag_007_003_008">BRE Expression Anchoring</a></xref>.<p><dt>ORD_CHAR<dd>A character, other than one of the special characters in SPEC_CHAR.<p><dt>QUOTED_CHAR<dd>In a BRE, one of the character sequences:<pre><dl compact><dt> <dd>\^      \.      \*      \[      \$      \\</dl></pre><p>In an ERE, one of the character sequences:<pre><dl compact><dt> <dd>\^      \.      \[      \$      \(      \)    \|\*      \+     \?      \{      \\</dl></pre><p><dt>R_ANCHOR<dd>(Applicable only to basic regular expressions.)The character "$" when it appears as the last character of abasic regular expression and when not QUOTED_CHAR.The "$" may be recognised as an anchor elsewhere; see<xref href=breanc><a href="#tag_007_003_008">BRE Expression Anchoring</a></xref>.<p><dt>SPEC_CHAR<dd>For basic regular expressions,will be one of the following special characters:<dl compact><dt>.<dd>anywhere outside bracket expressions<dt>\<dd>anywhere outside bracket expressions<dt>[<dd>anywhere outside bracket expressions<dt>^<dd>when used as an anchor (see<xref href=breanc><a href="#tag_007_003_008">BRE Expression Anchoring</a></xref>)or when first in a bracket expression<dt>$<dd>when used as an anchor<dt>*<dd>anywhere except:first in an entire RE;anywhere in a bracket expression;directly following\(;directly following an anchoring "^".</dl><p>For extended regular expressions,will be one of the following special characters found anywhereoutside bracket expressions:<pre><dl compact><dt> <dd>^    .    [    $    (    )    |    *    +    ?    {    \</dl></pre><p>(The close-parenthesis is considered special in this contextonly if matched with a preceding open-parenthesis.)<p></dl><h4><a name = "tag_007_005_002">&nbsp;</a>RE and Bracket Expression Grammar</h4>This section presents the grammar for basic regular expressions,including the bracket expression grammar that iscommon to both BREs and EREs.<code><pre>%token    ORD_CHAR QUOTED_CHAR DUP_COUNT%token    BACKREF L_ANCHOR R_ANCHOR%token    Back_open_paren  Back_close_paren/*          '\('             '\)'        */%token    Back_open_brace  Back_close_brace/*          '\{'             '\}'         *//* The following tokens are for the Bracket Expression   grammar common to both REs and EREs. */%token    COLL_ELEM META_CHAR%token    Open_equal Equal_close Open_dot Dot_close Open_colon Colon_close/*           '[='       '=]'        '[.'     '.]'      '[:'       ':]'  */%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 recognised between [: and :] */%start    basic_reg_exp%%/* --------------------------------------------   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_character_RE               | Back_open_paren RE_expression Back_close_paren               | Back_open_paren Back_close_paren               | BACKREF               ;one_character_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               ;/* --------------------------------------------   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               | collating_symbol               ;collating_symbol : Open_dot COLL_ELEM Dot_close               | Open_dot META_CHAR Dot_close               ;equivalence_class : Open_equal COLL_ELEM Equal_close               ;character_class : Open_colon class_name Colon_close               ;</code></pre><p>The BRE grammar does not permit L_ANCHOR or R_ANCHOR inside \(and \) (which implies that ^ and $ are ordinary characters).This reflects the semanticlimits on the application, as noted in<xref href=breanc><a href="#tag_007_003_008">BRE Expression Anchoring</a></xref>.Implementations are permitted to extend the language to interpret "^"and "$" as anchors in these locations, and assuch, portable applications cannot use unescaped "^" and "$"in positions inside\(and\)that might be interpreted as anchors.<h4><a name = "tag_007_005_003">&nbsp;</a>ERE Grammar</h4>This section presents the grammar for extended regular expressions,excluding the bracket expression grammar.<dl><dt><b>Note:</b><dd>The bracket expression grammar and the associated<b>%token</b>lines are identical between BREs and EREs.It has been omitted from the ERE section to avoid unnecessaryeditorial duplication.</dl><code><pre>%token  ORD_CHAR QUOTED_CHAR DUP_COUNT%start  extended_reg_exp%%/* --------------------------------------------   Extended Regular Expression   --------------------------------------------*/extended_reg_exp   :                          ERE_branch                   | extended_reg_exp '|' ERE_branch                   ;ERE_branch         :            ERE_expression                   | ERE_branch ERE_expression                   ;ERE_expression     : one_character_ERE                   | '^'                   | '$'                   | '(' extended_reg_exp ')'                   | ERE_expression ERE_dupl_symbol                   ;one_character_ERE  : ORD_CHAR                   | QUOTED_CHAR                   | '.'                   | bracket_expression                   ;ERE_dupl_symbol    : '*'                   | '+'                   | '?'                   | '{' DUP_COUNT               '}'                   | '{' DUP_COUNT ','           '}'                   | '{' DUP_COUNT ',' DUP_COUNT '}'                   ;</code></pre><p>The ERE grammar does not permit several constructs thatprevious sections specify as having undefined results:<ul><p><li>ORD_CHAR preceded by "\"<p><li>one or more ERE_dupl_symbols appearing first in an ERE, orimmediately following "|", "^" or "("<p><li>"{" not part of a valid ERE_dupl_symbol<p><li>"|" appearing first or last in an ERE, or immediately following"|" or "(", or immediately preceding ")".<p></ul><p>Implementations are permitted to extend the language to allow these.Portable applications cannot use such constructs.</blockquote><hr size=2 noshade><center><font size=2>UNIX &reg; is a registered Trademark of The Open Group.<br>Copyright &copy; 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 + -