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

📄 re.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<tr valign=top><td align=left>subexpressions/back-references<td align=left>\( \) \<i>n</i><tr valign=top><td align=left>single-character-BRE duplication<td align=left>* \{<i>m</i>,<i>n</i>\}<tr valign=top><td align=left>concatenation<td align=left>&nbsp;<tr valign=top><td align=left>anchoring<td align=left>^  $</table></pre><h4><a name = "tag_007_003_008">&nbsp;</a>BRE Expression Anchoring</h4><xref type="3" name="breanc"></xref>A BRE can be limited to matching strings that begin or end a line;this is called <i>anchoring</i>.The circumflex and dollar sign special characterswill be considered BRE anchors in the following contexts:<ol><p><li>A circumflex (^)is an anchor when used as the first character of an entire BRE.The implementation may treat circumflex as an anchorwhen used as the first character of a subexpression.The circumflex will anchor theexpression (or optionally subexpression)to the beginning of a string; only sequences starting at thefirst character of a string will be matched by the BRE.For example, the BRE^abmatchesabin the stringabcdef,but fails to match in the stringcdefab.The BRE\(^ab\)may match the former string.A portable BREmust escape a leading circumflex ina subexpression to match a literal circumflex.<p><li>A dollar sign($)is an anchor when used as the last character of an entire BRE.The implementation may treat a dollar sign as an anchorwhen used as the last character of a subexpression.The dollar sign will anchor theexpression (or optionally subexpression)to the end of the string beingmatched; the dollar sign can be said tomatch the end-of-string following the last character.<p><li>A BRE anchored by both "^" and "$" matches only an entire string.For example, the BRE^abcdef$matches strings consistingonly ofabcdef.<p></ol><h3><a name = "tag_007_004">&nbsp;</a>Extended Regular Expressions</h3><xref type="2" name="ere"></xref>The<i>extended regular expression</i>(ERE)notation and construction ruleswill apply to utilities defined as using extended regular expressions;any exceptions to the following rules are noted inthe descriptions of the specificutilities using EREs.<h4><a name = "tag_007_004_001">&nbsp;</a>EREs Matching a Single Character or Collating Element</h4>An ERE ordinary character, a special character preceded by a backslash or aperiod matches a single character.A bracket expression matches a single character or a singlecollating element.An <i>ERE matching a single character</i>enclosed in parentheses matches the same as theERE without parentheses would have matched.<h4><a name = "tag_007_004_002">&nbsp;</a>ERE Ordinary Characters</h4>An<i>ordinary character</i>is an ERE that matches itself.An ordinary character is any character in the supported character set,except for the ERE special characters listed in<xref href=erespec><a href="#tag_007_004_003">ERE Special Characters</a></xref>.The interpretation of an ordinary characterpreceded by a backslash(\)is undefined.<h4><a name = "tag_007_004_003">&nbsp;</a>ERE Special Characters</h4><xref type="3" name="erespec"></xref>An<i>ERE special character</i>has special properties in certain contexts.Outside those contexts, or when preceded by a backslash,such a character is an ERE thatmatches the special character itself.The extended regular expression special characters and the contexts in whichthey have their special meaning are:<dl compact><dt>. [ \ (<dd>The period, left-bracket, backslash and left-parenthesisare special except when used in abracket expression (see<xref href=rebrack><a href="#tag_007_003_005">RE Bracket Expression</a></xref>).Outside a bracket expression, a left-parenthesisimmediately followed by a right-parenthesis produces undefined results.<dt>)<dd>The right-parenthesis is special when matched with apreceding left-parenthesis, both outside a bracket expression.<dt>* + ? {<dd>The asterisk, plus-sign, question-mark and left-braceare special except when used in a bracket expression (see<xref href=rebrack><a href="#tag_007_003_005">RE Bracket Expression</a></xref>).Any of the following uses produce undefined results:<ul><li>if these characters appear first in an ERE,or immediately following a vertical-line, circumflex or left-parenthesis<li>if a left-brace is not part of a valid interval expression.</ul><dt>|<dd>The vertical-line is special except when used in a bracket expression (see<xref href=rebrack><a href="#tag_007_003_005">RE Bracket Expression</a></xref>).A vertical-line appearing first or last in an ERE, or immediately following avertical-line or a left-parenthesis,or immediately preceding a right-parenthesis,produces undefined results.<dt>^<dd>The circumflex is special when used:<ul><li>as an anchor(see<xref href=ereanc><a href="#tag_007_004_009">ERE Expression Anchoring</a></xref>)<li>as the first character of a bracket expression(see<xref href=rebrack><a href="#tag_007_003_005">RE Bracket Expression</a></xref>).</ul><dt>$<dd>The dollar sign is special when used as an anchor.</dl><h4><a name = "tag_007_004_004">&nbsp;</a>Periods in EREs</h4>A period(.),when used outside a bracket expression,is an ERE that matches anycharacter in the supported character set except NUL.<h4><a name = "tag_007_004_005">&nbsp;</a>ERE Bracket Expression</h4>The rules for ERE Bracket Expressions are the same as forBasic Regular Expressions; see<xref href=rebrack><a href="#tag_007_003_005">RE Bracket Expression</a></xref>.<h4><a name = "tag_007_004_006">&nbsp;</a>EREs Matching Multiple Characters</h4><p>The following rules will be used to constructEREs matching multiple charactersfrom EREs matching a single character:<ol><p><li>A <i>concatenation of EREs</i> matches theconcatenation of the character sequences matched byeach component of the ERE.A concatenation of EREs enclosed in parentheses matcheswhatever the concatenation without the parentheses matches.For example, both the EREcdand the ERE(cd)are matched by the third and fourth character of the stringabcdefabcdef.<p><li>When an ERE matching a single character or anERE enclosed in parentheses is followed by the special characterplus-sign (+), together with that plus-sign it matcheswhat one or more consecutive occurrences of the ERE would match.For example, the EREb+(bc)matches the fourth to seventhcharacters in the stringacabbbcde.And,[ab]+and[ab][ab]*are equivalent.<p><li>When an ERE matching a single character or anERE enclosed in parentheses is followed by the special character asterisk(*),together with that asterisk it matcheswhat zero or more consecutive occurrences of the ERE would match.For example, the EREb*cmatches the first characterin the stringcabbbcde,and the EREb*cdmatches the third to seventh characters in the stringcabbbcdebbbbbbcdbc.And,[ab]*and[ab][ab]are equivalent when matching the stringab.<p><li>When an ERE matching a single character or anERE enclosed in parentheses is followed by the special characterquestion-mark(?),together with that question-mark it matcheswhat zero or one consecutive occurrences of the ERE would match.For example, the EREb?cmatches the second character in the stringacabbbcde.<p><li>When an ERE matching a single character or anERE enclosed in parentheses is followed by an<i>interval expression</i>of the format{<i>m</i>}, {<i>m</i>,} or{<i>m</i>,<i>n</i>},together with that interval expressionit matcheswhat repeated consecutive occurrences of the ERE would match.The values of <i>m</i> and <i>n</i> will be decimal integers in the range0&lt;=<i>m</i>&lt;=<i>n</i>&lt;={RE_DUP_MAX},where <i>m</i> specifies the exact or minimum number ofoccurrences and <i>n</i> specifies the maximum number of occurrences.The expression {<i>m</i>} matches exactly <i>m</i>occurrences of the precedingERE,{<i>m</i>,} matches at least <i>m</i> occurrences and{<i>m</i>,<i>n</i>} matches any number of occurrences between<i>m</i> and <i>n</i>, inclusive.<p>For example, in the stringabababccccccdtheEREc{3}is matched by characters sevento nine and the ERE(ab){2,}is matched by characters one to six.<p></ol><p>The behaviour of multiple adjacent duplication symbols(+,*,?and intervals) produces undefined results.<h4><a name = "tag_007_004_007">&nbsp;</a>ERE Alternation</h4>Two EREs separated by the special character vertical-line (|)match a string that is matched by either.For example, the ERE a((bc)|d)matches the stringabcand the stringad.Single characters, or expressions matching single characters, separatedby the vertical bar and enclosed in parentheses, will be treated asan ERE matching a single character.<h4><a name = "tag_007_004_008">&nbsp;</a>ERE Precedence</h4>The order of precedence will be as shown in the following table:<pre><table  bordercolor=#000000 border=1 align=center><tr valign=top><th colspan=2 align=center><b>ERE Precedence (from high to low)</b><tr valign=top><td align=left>collation-related bracket symbols<td align=left>[= =]  [: :]  [. .]<tr valign=top><td align=left>escaped characters<td align=left>\&lt;<i>special character</i>&gt;<tr valign=top><td align=left>bracket expression<td align=left>[ ]<tr valign=top><td align=left>grouping<td align=left>( )<tr valign=top><td align=left>single-character-ERE duplication<td align=left>* + ? {<i>m</i>,<i>n</i>}<tr valign=top><td align=left>concatenation<td align=left>&nbsp;<tr valign=top><td align=left>anchoring<td align=left>^  $<tr valign=top><td align=left>alternation<td align=left>|</table></pre><p>For example, the EREabba|cdematches either the stringabbaor the stringcde(rather than the stringabbadeorabbcde,because concatenation has a higher order of precedence than alternation).<h4><a name = "tag_007_004_009">&nbsp;</a>ERE Expression Anchoring</h4><xref type="3" name="ereanc"></xref>An ERE can be limited to matching strings that begin or end a line;this is called <i>anchoring</i>.The circumflex and dollar sign special charactersare considered ERE anchorswhen used anywhere outside a bracket expression.This has the following effects:<ol><p><li>A circumflex(^)outside a bracket expression anchorsthe expression or subexpression it begins tothe beginning of a string;such an expression or subexpression can match onlya sequence starting at the first character of a string.For example, the EREs^aband(^ab)matchabin the stringabcdef,but fail to match in the stringcdefab,

⌨️ 快捷键说明

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