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

📄 parenconstructs.html

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 HTML
字号:
<HTML><HEAD><TITLE> Regular Expressions </TITLE></HEAD><BODY><A NAME="Parenthetical_Constructs"></A><H2> Parenthetical Constructs </H2><P><H3>Capturing Parentheses</H3></P><P>Capturing Parentheses are of the form `(&#60;regex&#62;)' and can be used to grouparbitrarily complex regular expressions.  Parentheses can be nested, but thetotal number of parentheses, nested or otherwise, is limited to 50 pairs. The text that is matched by the regular expression between a matched set ofparentheses is captured and available for text substitutions andbackreferences (see below.)  Capturing parentheses carry a fairly highoverhead both in terms of memory used and execution speed, especially ifquantified by `*' or `+'.</P><P><H3>Non-Capturing Parentheses</H3></P><P>Non-Capturing Parentheses are of the form `(?:&#60;regex&#62;)' and facilitategrouping only and do not incur the overhead of normal capturing parentheses. They should not be counted when determining numbers for capturing parentheseswhich are used with backreferences and substitutions.  Because of the limiton the number of capturing parentheses allowed in a regex, it is advisable touse non-capturing parentheses when possible.</P><P><H3>Positive Look-Ahead</H3></P><P>Positive look-ahead constructs are of the form `(?=&#60;regex&#62;)' and implement azero width assertion of the enclosed regular expression.  In other words, amatch of the regular expression contained in the positive look-aheadconstruct is attempted.  If it succeeds, control is passed to the nextregular expression atom, but the text that was consumed by the positivelook-ahead is first unmatched (backtracked) to the place in the text wherethe positive look-ahead was first encountered.</P><P>One application of positive look-ahead is the manual implementation of afirst character discrimination optimization.  You can include a positivelook-ahead that contains a character class which lists every character thatthe following (potentially complex) regular expression could possibly startwith.  This will quickly filter out match attempts that can not possiblysucceed.</P><P><H3>Negative Look-Ahead</H3></P><P>Negative look-ahead takes the form `(?!&#60;regex&#62;)' and is exactly the same aspositive look-ahead except that the enclosed regular expression must NOTmatch.  This can be particularly useful when you have an expression that isgeneral, and you want to exclude some special cases.  Simply precede thegeneral expression with a negative look-ahead that covers the special casesthat need to be filtered out.</P><P><H3>Positive Look-Behind</H3></P><P>Positive look-behind constructs are of the form `(?&#60;=&#60;regex&#62;)' and implementa zero width assertion of the enclosed regular expression in front of thecurrent matching position.  It is similar to a positive look-ahead assertion,except for the fact the the match is attempted on the text preceeding thecurrent position, possibly even in front of the start of the matching rangeof the entire regular expression.</P><P>A restriction on look-behind expressions is the fact that the expressionmust match a string of a bounded size.  In other words, `*', `+', and `{n,}'quantifiers are not allowed inside the look-behind expression. Moreover,matching performance is sensitive to the difference between the upper andlower bound on the matching size.  The smaller the difference, the better theperformance.  This is especially important for regular expressions used inhighlight patterns.</P><P>Another (minor) restriction is the fact that look-<B>ahead</B> patterns, norany construct that requires look-ahead information (such as word boundaries)are supported at the end of a look-behind pattern (no error is raised, butmatching behaviour is unspecified). It is always possible to place theselook-ahead patterns immediately after the look-behind pattern, where theywill work as expected.</P><P>Positive look-behind has similar applications as positive look-ahead.</P><P><H3>Negative Look-Behind</H3></P><P>Negative look-behind takes the form `(?&#60;!&#60;regex&#62;)' and is exactly the same aspositive look-behind except that the enclosed regular expression mustNOT match. The same restrictions apply.</P><P>Note however, that performance is even more sensitive to the distance between the size boundaries: a negative look-behind must not match for <B>any</B> possible size, so the matching engine must check <B>every</B> size.</P><P><H3>Case Sensitivity</H3></P><P>There are two parenthetical constructs that control case sensitivity:</P><P><PRE>     (?i&#60;regex&#62;)   Case insensitive; `AbcD' and `aBCd' are                   equivalent.</PRE></P><P><PRE>     (?I&#60;regex&#62;)   Case sensitive;   `AbcD' and `aBCd' are                   different.</PRE></P><P>Regular expressions are case sensitive by default, that is, `(?I&#60;regex&#62;)' isassumed.  All regular expression token types respond appropriately to caseinsensitivity including character classes and backreferences.  There is someextra overhead involved when case insensitivity is in effect, but only to theextent of converting each character compared to lower case.</P><P><H3>Matching Newlines</H3></P><P>NEdit regular expressions by default handle the matching of newlines in a waythat should seem natural for most editing tasks.  There are situations,however, that require finer control over how newlines are matched by someregular expression tokens.</P><P>By default, NEdit regular expressions will NOT match a newline character forthe following regex tokens: dot (`.'); a negated character class (`[^...]');and the following shortcuts for character classes:</P><P><PRE>     `\d', `\D', `\l', `\L', `\s', `\S', `\w', `\W', `\Y'</PRE></P><P>The matching of newlines can be controlled for the `.' token, negatedcharacter classes, and the `\s' and `\S' shortcuts by using one of thefollowing parenthetical constructs:</P><P><PRE>     (?n&#60;regex&#62;)  `.', `[^...]', `\s', `\S' match newlines</PRE></P><P><PRE>     (?N&#60;regex&#62;)  `.', `[^...]', `\s', `\S' don't match                                            newlines</PRE></P><P>`(?N&#60;regex&#62;)' is the default behavior.</P><P><H3>Notes on New Parenthetical Constructs</H3></P><P>Except for plain parentheses, none of the parenthetical constructs capturetext.  If that is desired, the construct must be wrapped with capturingparentheses, e.g. `((?i&#60;regex))'.</P><P>All parenthetical constructs can be nested as deeply as desired, except forcapturing parentheses which have a limit of 50 sets of parentheses,regardless of nesting level.</P><P><H3>Back References</H3></P><P>Backreferences allow you to match text captured by a set of capturingparenthesis at some later position in your regular expression.  Abackreference is specified using a single backslash followed by a singledigit from 1 to 9 (example: \3).  Backreferences have similar syntax tosubstitutions (see below), but are different from substitutions in that theyappear within the regular expression, not the substitution string. The numberspecified with a backreference identifies which set of text capturingparentheses the backreference is associated with. The text that was mostrecently captured by these parentheses is used by the backreference toattempt a match.  As with substitutions, open parentheses are counted fromleft to right beginning with 1.  So the backreference `\3' will try to matchanother occurrence of the text most recently matched by the third set ofcapturing parentheses.  As an example, the regular expression `(\d)\1' couldmatch `22', `33', or `00', but wouldn't match `19' or `01'.</P><P>A backreference must be associated with a parenthetical expression that iscomplete.  The expression `(\w(\1))' contains an invalid backreference sincethe first set of parentheses are not complete at the point where thebackreference appears.</P><P><H3>Substitution</H3></P><P>Substitution strings are used to replace text matched by a set of capturingparentheses.  The substitution string is mostly interpreted as ordinary textexcept as follows.</P><P>The escape sequences described above for special characters, and octal andhexadecimal escapes are treated the same way by a substitution string. Whenthe substitution string contains the `&#38;' character, NEdit will substitute theentire string that was matched by the `Find...' operation. Any of the firstnine sub-expressions of the match string can also be inserted into thereplacement string.  This is done by inserting a `\' followed by a digit from1 to 9 that represents the string matched by a parenthesized expressionwithin the regular expression.  These expressions are numbered left-to-rightin order of their opening parentheses.</P><P>The capitalization of text inserted by `&#38;' or `\1', `\2', ... `\9' can bealtered by preceding them with `\U', `\u', `\L', or `\l'.  `\u' and `\l'change only the first character of the inserted entity, while `\U' and `\L'change the entire entity to upper or lower case, respectively.<P><HR></P><P></P></BODY></HTML>

⌨️ 快捷键说明

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