cvs: phpdoc-zh /reference/pcre pattern.syntax.xml

From: Date: Thu, 26 Jan 2006 04:50:56 +0000
Subject: cvs: phpdoc-zh /reference/pcre pattern.syntax.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-2765@lists.php.net to get a copy of this message
dallas Thu Jan 26 04:50:56 2006 UTC Modified files: /phpdoc-zh/reference/pcre pattern.syntax.xml Log: More yet not completed.

http://cvs.php.net/viewcvs.cgi/phpdoc-zh/reference/pcre/pattern.syntax.xml?r1=1.5&r2=1.6&diff_format=u Index: phpdoc-zh/reference/pcre/pattern.syntax.xml diff -u phpdoc-zh/reference/pcre/pattern.syntax.xml:1.5 phpdoc-zh/reference/pcre/pattern.syntax.xml:1.6 --- phpdoc-zh/reference/pcre/pattern.syntax.xml:1.5 Sat Jan 14 04:16:15 2006 +++ phpdoc-zh/reference/pcre/pattern.syntax.xml Thu Jan 26 04:50:56 2006 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <!-- $Author: dallas $ --> <!-- EN-Revision: 1.13 Maintainer: dallas Status: partial --> <refentry id="reference.pcre.pattern.syntax"> @@ -657,131 +657,119 @@ <literal>\z</literal> ½öÆ¥Åä×Ö·û´®µÄ½áβ¡£ </para> <para> - The <literal>\G</literal> assertion is true only when the current - matching position is at the start point of the match, as specified by - the <parameter>offset</parameter> argument of - <function>preg_match</function>. It differs from <literal>\A</literal> - when the value of <parameter>offset</parameter> is non-zero. - It is available since PHP 4.3.3. + <literal>\G</literal> ¶ÏÑÔ½öÔÚµ±Ç°Æ¥ÅäλÖÃÊÇÆ¥Å俪ʼÄÇÒ»µãÊ±ÎªÕæ£¬Èç + <function>preg_match</function> µÄ <parameter>offset</parameter> + ²ÎÊýÖ¸¶¨ÄÇÑù¡£µ± <parameter>offset</parameter> + µÄÖµ·ÇÁãʱÕâºÍ <literal>\A</literal> ²»Í¬¡£×Ô PHP 4.3.3 Æð¿ÉÓᣠ</para> <para> - <literal>\Q</literal> and <literal>\E</literal> can be used to ignore - regexp metacharacters in the pattern since PHP 4.3.3. For example: - <literal>\w+\Q.$.\E$</literal> will match one or more word characters, - followed by literals <literal>.$.</literal> and anchored at the end of - the string. + <literal>\Q</literal> ºÍ <literal>\E</literal> ×Ô PHP 4.3.3 + Æð¿É±»ÓÃÀ´ÔÚģʽÖкöÂÔÕýÔò±í´ïʽƥÅä×Ö·û¡£ÀýÈ磺<literal>\w+\Q.$.\E$</literal> + ½«Æ¥ÅäÒ»¸ö»ò¶à¸ö¿É×é³É×ÖµÄ×Ö·û£¬Æäºó½Ó×ŵÄÊÇ×ÖÃæÉ쵀 <literal>.$.</literal> + ²¢ÇÒλÓÚ×Ö·û´®Ä©Î²¡£ </para> </refsect2> - <refsect2 id="regexp.reference.unicode"> - <title>Unicode character properties</title> - <para> - Since PHP 4.4.0 and 5.1.0, three - additional escape sequences to match generic character types are available - when <emphasis>UTF-8 mode</emphasis> is selected. They are: - </para> - <variablelist> - <varlistentry> - <term><emphasis>\p{xx}</emphasis></term> - <listitem><simpara>a character with the xx property</simpara></listitem> - </varlistentry> - <varlistentry> - <term><emphasis>\P{xx}</emphasis></term> - <listitem><simpara>a character without the xx property</simpara></listitem> - </varlistentry> - <varlistentry> - <term><emphasis>\X</emphasis></term> - <listitem><simpara>an extended Unicode sequence</simpara></listitem> - </varlistentry> - </variablelist> - <para> - The property names represented by <literal>xx</literal> above are limited to the Unicode - general category properties. Each character has exactly one such - property, specified by a two-letter abbreviation. For compatibility with - Perl, negation can be specified by including a circumflex between the - opening brace and the property name. For example, <literal>\p{^Lu}</literal> is the same - as <literal>\P{Lu}</literal>. - </para> - <para> - If only one letter is specified with <literal>\p</literal> or <literal>\P</literal>, it includes all the - properties that start with that letter. In this case, in the absence of - negation, the curly brackets in the escape sequence are optional; these - two examples have the same effect: - </para> - <literallayout> - \p{L} - \pL - </literallayout> - <table> - <title>Supported property codes</title> - <tgroup cols="2"> - <tbody> - <row><entry><literal>C</literal></entry><entry>Other</entry></row> - <row><entry><literal>Cc</literal></entry><entry>Control</entry></row> - <row><entry><literal>Cf</literal></entry><entry>Format</entry></row> - <row><entry><literal>Cn</literal></entry><entry>Unassigned</entry></row> - <row><entry><literal>Co</literal></entry><entry>Private use</entry></row> - <row rowsep="1"><entry><literal>Cs</literal></entry><entry>Surrogate</entry></row> - <row><entry><literal>L</literal></entry><entry>Letter</entry></row> - <row><entry><literal>Ll</literal></entry><entry>Lower case letter</entry></row> - <row><entry><literal>Lm</literal></entry><entry>Modifier letter</entry></row> - <row><entry><literal>Lo</literal></entry><entry>Other letter</entry></row> - <row><entry><literal>Lt</literal></entry><entry>Title case letter</entry></row> - <row rowsep="1"><entry><literal>Lu</literal></entry><entry>Upper case letter</entry></row> - <row><entry><literal>M</literal></entry><entry>Mark</entry></row> - <row><entry><literal>Mc</literal></entry><entry>Spacing mark</entry></row> - <row><entry><literal>Me</literal></entry><entry>Enclosing mark</entry></row> - <row rowsep="1"><entry><literal>Mn</literal></entry><entry>Non-spacing mark</entry></row> - <row><entry><literal>N</literal></entry><entry>Number</entry></row> - <row><entry><literal>Nd</literal></entry><entry>Decimal number</entry></row> - <row><entry><literal>Nl</literal></entry><entry>Letter number</entry></row> - <row rowsep="1"><entry><literal>No</literal></entry><entry>Other number</entry></row> - <row><entry><literal>P</literal></entry><entry>Punctuation</entry></row> - <row><entry><literal>Pc</literal></entry><entry>Connector punctuation</entry></row> - <row><entry><literal>Pd</literal></entry><entry>Dash punctuation</entry></row> - <row><entry><literal>Pe</literal></entry><entry>Close punctuation</entry></row> - <row><entry><literal>Pf</literal></entry><entry>Final punctuation</entry></row> - <row><entry><literal>Pi</literal></entry><entry>Initial punctuation</entry></row> - <row><entry><literal>Po</literal></entry><entry>Other punctuation</entry></row> - <row rowsep="1"><entry><literal>Ps</literal></entry><entry>Open punctuation</entry></row> - <row><entry><literal>S</literal></entry><entry>Symbol</entry></row> - <row><entry><literal>Sc</literal></entry><entry>Currency symbol</entry></row> - <row><entry><literal>Sk</literal></entry><entry>Modifier symbol</entry></row> - <row><entry><literal>Sm</literal></entry><entry>Mathematical symbol</entry></row> - <row rowsep="1"><entry><literal>So</literal></entry><entry>Other symbol</entry></row> - <row><entry><literal>Z</literal></entry><entry>Separator</entry></row> - <row><entry><literal>Zl</literal></entry><entry>Line separator</entry></row> - <row><entry><literal>Zp</literal></entry><entry>Paragraph separator</entry></row> - <row><entry><literal>Zs</literal></entry><entry>Space separator</entry></row> - </tbody> - </tgroup> - </table> - <para> - Extended properties such as "Greek" or "InMusicalSymbols" are not - supported by PCRE. - </para> - <para> - Specifying caseless matching does not affect these escape sequences. - For example, <literal>\p{Lu}</literal> always matches only upper case letters. - </para> - <para> - The <literal>\X</literal> escape matches any number of Unicode characters that form an - extended Unicode sequence. <literal>\X</literal> is equivalent to - <literal>(?>\PM\pM*)</literal>. - </para> - <para> - That is, it matches a character without the "mark" property, followed - by zero or more characters with the "mark" property, and treats the - sequence as an atomic group (see below). Characters with the "mark" - property are typically accents that affect the preceding character. - </para> - <para> - Matching characters by Unicode property is not fast, because PCRE has - to search a structure that contains data for over fifteen thousand - characters. That is why the traditional escape sequences such as <literal>\d</literal> and - <literal>\w</literal> do not use Unicode properties in PCRE. - </para> - </refsect2> + <refsect2 id="regexp.reference.unicode"> + <title>Unicode ×Ö·ûÊôÐÔ</title> + <para> + ×Ô PHP 4.4.0 ºÍ 5.1.0 Æð£¬µ±Ñ¡ÔñÁË + additional escape sequences to match generic character types are available + <emphasis>UTF-8 ģʽ</emphasis>ʱÓÐÈýÖÖ¸ü¶àµÄ×ªÒÆÐòÁпÉÓ㺠+ </para> + <variablelist> + <varlistentry> + <term><emphasis>\p{xx}</emphasis></term> + <listitem><simpara>¾ßÓÐ xx ÊôÐÔµÄÒ»¸ö×Ö·û</simpara></listitem> + </varlistentry> + <varlistentry> + <term><emphasis>\P{xx}</emphasis></term> + <listitem><simpara>ûÓÐ xx ÊôÐÔµÄÒ»¸ö×Ö·û</simpara></listitem> + </varlistentry> + <varlistentry> + <term><emphasis>\X</emphasis></term> + <listitem><simpara>Ò»¸öÀ©Õ¹ Unicode ÐòÁÐ</simpara></listitem> + </varlistentry> + </variablelist> + <para> + ÒÔÉÏÓÉ <literal>xx</literal> Ëù±íʾµÄÊôÐÔÃûÏÞÓÚ Unicode + ͨÓÃÀàÐÍÊôÐÔ¡£Ã¿¸ö×Ö·û¾ßÓÐÒ»¸ö´ËÖÖÊôÐÔ£¬ÓÉÁ½¸öËõд×Öĸָ¶¨¡£ÎªºÍ + Perl ¼æÈÝ£¬¿ÉÒÔÔÚ×ó»¨À¨ºÅºÍÊôÐÔÃûÖмä¼ÓÈëÒ»¸öÉϼýÍ··ûºÅÀ´±íʾÅųýÊôÐÔ¡£ÀýÈç + <literal>\p{^Lu}</literal> ¾ÍºÍ <literal>\P{Lu}</literal> Ïàͬ¡£ + </para> + <para> + Èç¹ûÔÚ <literal>\p</literal> »ò <literal>\P</literal> + ÖÐÖ»ÓÃÁËÒ»¸ö×Öĸ£¬Ôò°üÀ¨ÁËËùÓиÃ×Öĸ¿ªÍ·µÄÊôÐÔ¡£´ËÇé¿öÏ£¬Èç¹û²»ÊÇÅųýµÄ»°£¬¿ÉÒÔÊ¡ÂÔ»¨À¨ºÅ¡£ÏÂÃæÀý×ÓÖеÄÁ½Ïî¾ßÓÐÏàͬЧ¹û£º + </para> + <literallayout> + \p{L} + \pL + </literallayout> + <table> + <title>ËùÖ§³ÖµÄÊôÐÔ´úÂë</title> + <tgroup cols="2"> + <tbody> + <row><entry><literal>C</literal></entry><entry>Other - ÆäËü</entry></row> + <row><entry><literal>Cc</literal></entry><entry>Control - ¿ØÖÆ</entry></row> + <row><entry><literal>Cf</literal></entry><entry>Format - ¸ñʽ</entry></row> + <row><entry><literal>Cn</literal></entry><entry>Unassigned - ÎÞ·ûºÅ</entry></row> + <row><entry><literal>Co</literal></entry><entry>Private use - ˽ÓÐ</entry></row> + <row rowsep="1"><entry><literal>Cs</literal></entry><entry>Surrogate - ´úÌæ</entry></row> + <row><entry><literal>L</literal></entry><entry>Letter -×Öĸ</entry></row> + <row><entry><literal>Ll</literal></entry><entry>Lower case letter - Сд×Öĸ</entry></row> + <row><entry><literal>Lm</literal></entry><entry>Modifier letter - ÐÞÕý·û×Öĸ</entry></row> + <row><entry><literal>Lo</literal></entry><entry>Other letter - ÆäËü×Öĸ</entry></row> + <row><entry><literal>Lt</literal></entry><entry>Title case letter - ±êÌâ´óд×Öĸ</entry></row> + <row rowsep="1"><entry><literal>Lu</literal></entry><entry>Upper case letter - ´óд×Öĸ</entry></row> + <row><entry><literal>M</literal></entry><entry>Mark - ±ê¼Ç</entry></row> + <row><entry><literal>Mc</literal></entry><entry>Spacing mark - ¿Õ¸ñ±ê¼Ç</entry></row> + <row><entry><literal>Me</literal></entry><entry>Enclosing mark - »·ÈƱê¼Ç</entry></row> + <row rowsep="1"><entry><literal>Mn</literal></entry><entry>Non-spacing mark - ·Ç¿Õ¸ñ±ê¼Ç</entry></row> + <row><entry><literal>N</literal></entry><entry>Number - Êý×Ö</entry></row> + <row><entry><literal>Nd</literal></entry><entry>Decimal number - Ê®½øÖÆÊý×Ö</entry></row> + <row><entry><literal>Nl</literal></entry><entry>Letter number - ×ÖĸÊý×Ö</entry></row> + <row rowsep="1"><entry><literal>No</literal></entry><entry>Other number - ÆäËüÊý×Ö</entry></row> + <row><entry><literal>P</literal></entry><entry>Punctuation - ±êµã·ûºÅ</entry></row> + <row><entry><literal>Pc</literal></entry><entry>Connector punctuation - Á¬½Ó±êµã·û</entry></row> + <row><entry><literal>Pd</literal></entry><entry>Dash punctuation - ºáÏß±êµã·û</entry></row> + <row><entry><literal>Pe</literal></entry><entry>Close punctuation - ½áÊø±êµã·û</entry></row> + <row><entry><literal>Pf</literal></entry><entry>Final punctuation - ×îÖÕ±êµã·û</entry></row> + <row><entry><literal>Pi</literal></entry><entry>Initial punctuation - Æðʼ±êµã·û</entry></row> + <row><entry><literal>Po</literal></entry><entry>Other punctuation - ÆäËü±êµã·ûºÅ</entry></row> + <row rowsep="1"><entry><literal>Ps</literal></entry><entry>Open punctuation - ¿ªÊ¼±êµã·û</entry></row> + <row><entry><literal>S</literal></entry><entry>Symbol - ·ûºÅ</entry></row> + <row><entry><literal>Sc</literal></entry><entry>Currency symbol - »õ±Ò·ûºÅ</entry></row> + <row><entry><literal>Sk</literal></entry><entry>Modifier symbol - ÐÞÕý·ûºÅ</entry></row> + <row><entry><literal>Sm</literal></entry><entry>Mathematical symbol - ËãÊõ·ûºÅ</entry></row> + <row rowsep="1"><entry><literal>So</literal></entry><entry>Other symbol - ÆäËü·ûºÅ</entry></row> + <row><entry><literal>Z</literal></entry><entry>Separator - ·Ö¸ô·û</entry></row> + <row><entry><literal>Zl</literal></entry><entry>Line separator - Ðзָô·û</entry></row> + <row><entry><literal>Zp</literal></entry><entry>Paragraph separator - ¶ÎÂä·Ö¸ô·û</entry></row> + <row><entry><literal>Zs</literal></entry><entry>Space separator - ¿Õ¸ñ·Ö¸ô·û</entry></row> + </tbody> + </tgroup> + </table> + <para> + PCRE ²»Ö§³ÖÀ©Õ¹ÊôÐÔÀýÈç "Greek" »ò "InMusicalSymbols"¡£ + </para> + <para> + Ö¸¶¨²»Çø·Ö´óСдµÄÆ¥Åä²»Ó°Ïì´ËÀàתÒåÐòÁС£ÀýÈç <literal>\p{Lu}</literal> + ×ÜÊǽöºÍ´óд×ÖĸƥÅä¡£ + </para> + <para> + <literal>\X</literal> ×ªÒÆ·ûÆ¥ÅäÄÜ×é³ÉÀ©Õ¹ Unicode ÐòÁеÄÈκÎÊýÄ¿µÄ Unicode ×Ö·û¡£<literal>\X</literal> + ºÍ <literal>(?>\PM\pM*)</literal> Ïàͬ¡£ + </para> + <para> + Ò²¾ÍÊÇ£¬ËüÆ¥ÅäÒ»¸öûÓС°mark¡±ÊôÐÔ£¬ºóÃæ¸ú×ÅÁã»ò¶à¸ö¾ßÓС°mark¡±ÊôÐÔµÄ×Ö·û£¬²¢ÇÒ½«´ËÐòÁп´³ÉÔ­×Ó×飨¼ûÏ£©¡£µäÐ͵ľßÓС°mark¡±ÊôÐÔµÄ×ÖĸÊÇÓ°Ïìµ½Ç°ÃæµÄ×Ö·ûµÄÖØÒô·û¡£ + </para> + <para> + Óà Unicode ÊôÐÔÀ´Æ¥Åä×Ö·û²¢²»¿ì£¬ÒòΪ PCRE + ²»µÃ²»ËÑË÷Ò»¸ö°üº¬³¬¹ýÒ»ÍòÎåǧ×Ö·ûÊý¾ÝµÄ½á¹¹¡£ÕâÕýÊÇΪʲôÔÚ + PCRE Öд«Í³µÄתÒåÐòÁÐÀýÈç <literal>\d</literal> ºÍ + <literal>\w</literal> ²»Ê¹Óà Unicode ÊôÐÔ¡£ + </para> + </refsect2> <refsect2 id="regexp.reference.circudollar"> <title>Òôµ÷·û£¨^£©ºÍÃÀÔª·û£¨$£©</title> @@ -1007,195 +995,120 @@ ÒÔ¼° "king"£¬²¢±»¼ÆÎª 1£¬2 ºÍ 3¡£ </para> <para> - The fact that plain parentheses fulfil two functions is not - always helpful. There are often times when a grouping subpattern - is required without a capturing requirement. If an - opening parenthesis is followed by "?:", the subpattern does - not do any capturing, and is not counted when computing the - number of any subsequent capturing subpatterns. For example, - if the string "the white queen" is matched against the - pattern - - <literal>the ((?:red|white) (king|queen))</literal> - - the captured substrings are "white queen" and "queen", and - are numbered 1 and 2. The maximum number of captured substrings - is 99, and the maximum number of all subpatterns, - both capturing and non-capturing, is 200. - </para> - <para> - As a convenient shorthand, if any option settings are - required at the start of a non-capturing subpattern, the - option letters may appear between the "?" and the ":". Thus - the two patterns - </para> + ¼òµ¥µÄÀ¨ºÅʵÏÖÁ½ÖÖ¹¦ÄܵÄÊÂʵ²»×ÜÊÇÓаïÖúµÄ¡£¾­³£ÓÐÐèÒªÒ»×é×Óģʽµ«²»ÐèÒª²¶»ñµÄʱºò¡£Èç¹û×óÀ¨ºÅºóÃæ¸ú×Å + "?:"£¬×Óģʽ²»×öÈκβ¶»ñ£¬²¢ÇÒÔÚ¼ÆËãÈκÎÖ®ºó²¶»ñµÄ×ÓģʽʱҲ²»ËãÔÚÄÚ¡£ÀýÈ磬Èç¹ûÓÃ×Ö·û´® + "the white queen" È¥ºÍģʽ <literal>the ((?:red|white) (king|queen))</literal> Æ¥Å䣬²¶»ñµÄ×Ó´®ÊÇ + "white queen" ºÍ "queen"£¬²¢±»¼ÆÎª 1 ºÍ 2¡£Ëù²¶»ñµÄ×Ó´®µÄ×î´óÊýÄ¿ÊÇ + 99£¬ËùÓÐ×Óģʽ£¬°üÀ¨²¶»ñµÄºÍû²¶»ñµÄ£¬×î´óÊýÄ¿ÊÇ 200¡£ + </para> + <para> + ×÷Ϊ·½±ãµÄËټǣ¬Èç¹ûÔڷDz¶»ñ×ÓģʽµÄ¿ªÍ·ÐèÒªÈκÎÑ¡ÏîÉ趨£¬ÔòÑ¡Ïî×Öĸ¿ÉÒÔ³öÏÖÔÚ + "?" ºÍ ":" Öм䡣Òò´ËÏÂÃæÁ½¸öģʽ + </para> - <literallayout> + <literallayout> (?i:saturday|sunday) (?:(?i)saturday|sunday) - </literallayout> - - <para> - match exactly the same set of strings. Because alternative - branches are tried from left to right, and options are not - reset until the end of the subpattern is reached, an option - setting in one branch does affect subsequent branches, so - the above patterns match "SUNDAY" as well as "Saturday". - </para> - - <para> - It is possible to name the subpattern with - <literal>(?P&lt;name&gt;pattern)</literal> since PHP 4.3.3. Array with matches will - contain the match indexed by the string alongside the match indexed by - a number, then. - </para> - </refsect2> - - <refsect2 id="regexp.reference.repetition"> - <title>Repetition</title> - <para> - Repetition is specified by quantifiers, which can follow any - of the following items: - - <itemizedlist> - <listitem><simpara>a single character, possibly escaped</simpara></listitem> - <listitem><simpara>the . metacharacter</simpara></listitem> - <listitem><simpara>a character class</simpara></listitem> - <listitem><simpara>a back reference (see next section)</simpara></listitem> - <listitem><simpara>a parenthesized subpattern (unless it is an assertion - - see below)</simpara></listitem> - </itemizedlist> - </para> - <para> - The general repetition quantifier specifies a minimum and - maximum number of permitted matches, by giving the two - numbers in curly brackets (braces), separated by a comma. - The numbers must be less than 65536, and the first must be - less than or equal to the second. For example: - - <literal>z{2,4}</literal> - - matches "zz", "zzz", or "zzzz". A closing brace on its own - is not a special character. If the second number is omitted, - but the comma is present, there is no upper limit; if the - second number and the comma are both omitted, the quantifier - specifies an exact number of required matches. Thus - - <literal>[aeiou]{3,}</literal> - - matches at least 3 successive vowels, but may match many - more, while - - <literal>\d{8}</literal> - - matches exactly 8 digits. An opening curly bracket that - appears in a position where a quantifier is not allowed, or - one that does not match the syntax of a quantifier, is taken - as a literal character. For example, {,6} is not a quantifier, - but a literal string of four characters. - </para> - <para> - The quantifier {0} is permitted, causing the expression to - behave as if the previous item and the quantifier were not - present. - </para> - <para> - For convenience (and historical compatibility) the three - most common quantifiers have single-character abbreviations: - - <table> - <title>Single-character quantifiers</title> - <tgroup cols="2"> - <tbody> - <row> - <entry><literal>*</literal></entry> - <entry>equivalent to <literal>{0,}</literal></entry> - </row> - <row> - <entry><literal>+</literal></entry> - <entry>equivalent to <literal>{1,}</literal></entry> - </row> - <row> - <entry><literal>?</literal></entry> - <entry>equivalent to <literal>{0,1}</literal></entry> - </row> - </tbody> - </tgroup> - </table> - </para> - <para> - It is possible to construct infinite loops by following a - subpattern that can match no characters with a quantifier - that has no upper limit, for example: + </literallayout> - <literal>(a?)*</literal> - </para> - <para> - Earlier versions of Perl and PCRE used to give an error at - compile time for such patterns. However, because there are - cases where this can be useful, such patterns are now - accepted, but if any repetition of the subpattern does in - fact match no characters, the loop is forcibly broken. - </para> - <para> - By default, the quantifiers are "greedy", that is, they - match as much as possible (up to the maximum number of permitted - times), without causing the rest of the pattern to - fail. The classic example of where this gives problems is in - trying to match comments in C programs. These appear between - the sequences /* and */ and within the sequence, individual - * and / characters may appear. An attempt to match C comments - by applying the pattern - - <literal>/\*.*\*/</literal> - - to the string + <para> + Æ¥ÅäÁËÍêÈ«ÏàͬµÄÒ»×é×Ö·û´®¡£ÒòΪ·ÖÖ§Ñ¡ÏîÊÇ´Ó×óÏòÓÒ³¢ÊԵ쬲¢ÇÒÖ±µ½×Óģʽ½áÊøÇ°¶¼²»»áÖØÖÃÑ¡ÏÒò´ËÔÚÒ»¸ö·ÖÖ§ÖеÄÑ¡ÏîÉ趨»áÓ°Ïìµ½Ö®ºóµÄ·ÖÖ§£¬ËùÒÔÒÔÉÏģʽ»áÆ¥Åä + "SUNDAY" ºÍ "Saturday"¡£ + </para> - <literal>/* first comment */ not comment /* second comment */</literal> + <para> + ×Ô PHP 4.3.3 ÆðÓпÉÄÜͨ¹ý <literal>(?P&lt;name&gt;pattern)</literal> + À´¸øÒ»¸öģʽÃüÃû¡£Æ¥Åä½á¹ûµÄÊý×é»áͬʱ°üº¬ÒÔģʽÃûΪË÷ÒýºÍÒÔÊý×ÖΪË÷ÒýµÄ²¿·Ö¡£ + </para> + </refsect2> - fails, because it matches the entire string due to the - greediness of the .* item. - </para> - <para> - However, if a quantifier is followed by a question mark, - then it ceases to be greedy, and instead matches the minimum - number of times possible, so the pattern + <refsect2 id="regexp.reference.repetition"> + <title>ÖØ¸´</title> + <para> + ÖØ¸´ÊÇÓÉÊýÁ¿·ûÖ¸¶¨µÄ£¬¿ÉÒÔ½ÓÒÔÏÂÈκÎÒ»Ï + <itemizedlist> + <listitem><simpara>µ¥¸ö×Ö·û£¬¿ÉÒÔÊDZ»×ªÒåµÄ</simpara></listitem> + <listitem><simpara>. Æ¥Åä×Ö·û</simpara></listitem> + <listitem><simpara>Ò»Àà×Ö·û</simpara></listitem> + <listitem><simpara>Ò»¸ö·´ÏòÒýÓ㨼ûÏÂÒ»½Ú£©</simpara></listitem> + <listitem><simpara>Ò»¸öÀ¨ºÅÖеÄ×Óģʽ£¨³ý·ÇÊǸö¶ÏÑÔ - ¼ûÏ£©</simpara></listitem> + </itemizedlist> + </para> + <para> + ÆÕͨµÄÖØ¸´ÊýÁ¿·ûÖ¸¶¨ÁËËùÔÊÐíµÄÆ¥ÅäµÄ×îСºÍ×î´óÊýÄ¿£¬·½·¨Êǽ«Á½¸öÊý×Ö·ÅÔÚ»¨À¨ºÅÖУ¬ÖмäÓöººÅ·Ö¸ô¡£Êý×Ö±ØÐëСÓÚ + 65536£¬²¢ÇÒµÚÒ»¸öÊý×Ö±ØÐëСÓÚ»òµÈÓÚµÚ¶þ¸öÊý×Ö¡£ÀýÈ磺<literal>z{2,4}</literal> + Æ¥ÅäÁË "zz"£¬"zzz" »ò "zzzz"¡£µ¥¸öµÄÓÒ»¨À¨ºÅ²»ËãÊÇÌØÊâ×Ö·û¡£Èç¹ûÊ¡ÂÔÁ˵ڶþ¸öÊý×Öµ«ÊÇÓжººÅ£¬Ôò±íʾûÓÐÉÏÏÞ¡£Èç¹ûͬʱʡÂÔÁ˵ڶþ¸öÊý×ֺͶººÅ£¬ÔòÊýÁ¿·ûÖ¸¶¨ÁËÆ¥ÅäµÄ׼ȷÊýÄ¿¡£Òò´Ë + <literal>[aeiou]{3,}</literal> Æ¥ÅäÖÁÉÙÁ¬Ðø 3 ¸öÔªÒô£¬µ«ÊÇ¿ÉÒÔÆ¥Åä¸ü¶à¡£<literal>\d{8}</literal> + ÔòÆ¥ÅäÁËÕýºÃ 8 ¸öÊý×Ö¡£³öÏÖÔÚ²»ÔÊÐí·ÅÖÃÊýÁ¿·ûλÖûòÕß²»·ûºÏÊýÁ¿·ûÓï·¨µÄ×ó»¨À¨ºÅ£¬±»µ±³É×ÖÃæÉϵĸÃ×Ö·û¡£ÀýÈç + {,6} ²»ÊÇÒ»¸öÊýÁ¿·û£¬¶øÊÇ×ÖÃæÉϵÄÕâËĸö×Ö·û¡£ + </para> + <para> + ÊýÁ¿·û {0} ÊÇÔÊÐíµÄ£¬µ¼Ö±í´ïʽÀí½âΪǰһÏîºÍÊýÁ¿·û²»´æÔÚ¡£ + </para> + <para> + Ϊ·½±ãÆð¼û£¨ÒÔ¼°ÀúÊ·ÐԵļæÈÝ£©£¬Èý¸ö×î³£ÓõÄÊýÁ¿·û¶¼Óе¥×Ö·ûµÄËõд£º + <table> + <title>µ¥×Ö·ûÊýÁ¿·û</title> + <tgroup cols="2"> + <tbody> + <row> + <entry><literal>*</literal></entry> + <entry>µÈͬÓÚ <literal>{0,}</literal></entry> + </row> + <row> + <entry><literal>+</literal></entry> + <entry>µÈͬÓÚ <literal>{1,}</literal></entry> + </row> + <row> + <entry><literal>?</literal></entry> + <entry>µÈͬÓÚ <literal>{0,1}</literal></entry> + </row> + </tbody> + </tgroup> + </table> + </para> + <para> + ÓпÉÄÜͨ¹ýÔÚÒ»¸ö²»Æ¥ÅäÈκÎ×Ö·ûµÄ×ÓģʽºóÃæ¸úÒ»¸öûÓÐÉÏÏÞµÄÊýÁ¿·û¹¹Ôì³öÎÞÏÞÑ­»·£¬ÀýÈ磺<literal>(a?)*</literal>¡£ + </para> + <para> + ¶Ô´ËÀàģʽÔçÆÚ°æ±¾µÄ Perl ºÍ PCRE + »áÔÚ±àÒëʱ¸ø³ö´íÎó¡£²»¹ýÓÉÓÚÕâÔÚijЩÇé¿öÏÂÓÐÓã¬Èç½ñÒѾ­½ÓÊÜ´ËÖÖģʽÁË£¬µ«ÊÇÈç¹ûÈκÎ×ÓģʽµÄÖØ¸´È·Êµ²»Æ¥ÅäÈκÎ×Ö·û£¬ÔòÑ­»·»á±»Ç¿ÖÆ´ò¶Ï¡£ + </para> + <para> + ĬÈÏʱ£¬ÊýÁ¿·ûÊÇ¡°Ì°³ÔÐÍ¡±£¨greedy£©µÄ£¬¼´»áÔÚ²»µ¼ÖÂÊ£Óàģʽʧ°ÜµÄÇé¿öϾ¡¿ÉÄÜ¶àµØÆ¥Å䣨ֱµ½ËùÔÊÐíµÄÊýÄ¿ÉÏÏÞ£©¡£Õâ»á³öÎÊÌâµÄ¾­µäÀý×ÓÊdz¢ÊÔÆ¥Åä + C ÓïÑÔµÄ×¢ÊÍ¡£ÔÚ /* ºÍ */ ÐòÁÐÖм䣬¿ÉÄÜ»á³öÏÖµ¥¸öµÄ * + ºÍ / ×Ö·û¡£¶Ô C ×¢ÊÍÈç¹ûÊÔͼÓà <literal>/\*.*\*/</literal> + È¥ºÍ×Ö·û´® <literal>/* first comment */ not comment /* second comment */</literal> + Æ¥Åä»áʧ°Ü£¬ÒòΪÓÉÓÚ .* ÏîÄ¿µÄ̰³ÔÐÔ£¬»áÆ¥Åä³ÉÕû¸ö×Ö·û´®¡£ + </para> + <para> + ²»¹ý£¬Èç¹ûÔÚºóÃæ¼ÓÒ»¸öÎʺÅÊýÁ¿·û£¬Ôò»áֹ̰ͣ³ÔÐÔ£¬¶ø±ä³ÉÆ¥Å価¿ÉÄÜÉÙµÄÊýÄ¿£¬Òò´Ëģʽ <literal>/\*.*?\*/</literal> - does the right thing with the C comments. The meaning of the - various quantifiers is not otherwise changed, just the preferred - number of matches. Do not confuse this use of - question mark with its use as a quantifier in its own right. - Because it has two uses, it can sometimes appear doubled, as - in + ¾Í»áÕýÈ·Æ¥Åä C ×¢ÊÍ¡£¸÷ÖÖÊýÁ¿·ûµÄº¬Ò岢ûÓиı䣬ֻÊÇÓÅÏÈµÄÆ¥ÅäÊýÄ¿¡£²»Òª½«ÎʺŵĴËÓ÷¨ºÍÆä×Ô¼º×÷ΪÊýÁ¿·ûµÄʹÓûìÏý¡£ÒòΪÓÐÁ½ÖÖÓ÷¨£¬ÓÐʱ¿ÉÒÔÁ½¸öÒ»Æð³öÏÖ£¬ÀýÈç <literal>\d??\d</literal> - which matches one digit by preference, but can match two if - that is the only way the rest of the pattern matches. - </para> - <para> - If the <link linkend="reference.pcre.pattern.modifiers">PCRE_UNGREEDY</link> option is set (an option which is not - available in Perl) then the quantifiers are not greedy by - default, but individual ones can be made greedy by following - them with a question mark. In other words, it inverts the - default behaviour. - </para> - <para> - Quantifiers followed by <literal>+</literal> are "possessive". They eat - as many characters as possible and don't return to match the rest of the - pattern. Thus <literal>.*abc</literal> matches "aabc" but - <literal>.*+abc</literal> doesn't because <literal>.*+</literal> eats the - whole string. Possessive quantifiers can be used to speed up processing since PHP 4.3.3. - </para> - <para> + »áÓÅÏÈÆ¥ÅäÒ»¸öÊý×Ö£¬µ«Èç±ðÎÞÑ¡ÔñÒ²¿ÉÒÔÆ¥ÅäÁ½¸öÒÔʹʣÓàģʽƥÅä¡£ + </para> + <para> + Èç¹ûÉ趨ÁË <link linkend="reference.pcre.pattern.modifiers">PCRE_UNGREEDY</link> Ñ¡Ï´ËÑ¡Ïî Perl + ÖÐûÓУ©ÔòÊýÁ¿·ûĬÈϲ»ÊÇ̰³ÔÐ͵쬵«ÊÇÔÚ¸ö±ðģʽºó¼ÓÉÏÒ»¸öÎʺſÉÒÔ½«Æä±ä³Ḛ́³ÔÐ͵ġ£»»¾ä»°Ëµ£¬Õâ¿ÉÒÔ·´×ªÄ¬ÈϵÄÐÐΪ¡£ + </para> + <para> + ºóÃæ¸úÉÏÒ»¸ö <literal>+</literal> µÄÊýÁ¿·ûÊÇ¡°Õ¼ÓÐÐÔ¡±£¨possessive£©µÄ¡£Ëü»áÆ¥Å価¿ÉÄܶàµÄ×Ö·û¶ø²»¹ÜÊ£ÓàµÄģʽ¡£Òò´Ë + <literal>.*abc</literal> ¿ÉÒÔÆ¥Åä "aabc" µ«ÊÇ + <literal>.*+abc</literal> ¾Í²»»á£¬ÒòΪ <literal>.*+</literal> + ÒѾ­Æ¥ÅäÁËÕû¸ö×Ö·û´®¡£×Ô PHP 4.3.3 Æð¿ÉÒÔÓÃÕ¼ÓÐÐÔÊýÁ¿·û¿ÉÒÔÀ´¼Ó¿ì´¦Àí¹ý³Ì¡£ + </para> + <para> When a parenthesized subpattern is quantified with a minimum repeat count that is greater than 1 or with a limited maximum, more store is required for the compiled pattern, in proportion to the size of the minimum or maximum. - </para> - <para> + </para> + <para> If a pattern starts with .* or .{0,} and the <link linkend="reference.pcre.pattern.modifiers">PCRE_DOTALL</link> option (equivalent to Perl's /s) is set, thus allowing the . to match newlines, then the pattern is implicitly anchored, @@ -1207,8 +1120,8 @@ no newlines, it is worth setting <link linkend="reference.pcre.pattern.modifiers">PCRE_DOTALL</link> when the pattern begins with .* in order to obtain this optimization, or alternatively using ^ to indicate anchoring explicitly. - </para> - <para> + </para> + <para> When a capturing subpattern is repeated, the value captured is the substring that matched the final iteration. For example, after @@ -1224,19 +1137,19 @@ matches "aba" the value of the second captured substring is "b". - </para> - </refsect2> + </para> + </refsect2> - <refsect2 id="regexp.reference.back-references"> - <title>Back references</title> - <para> + <refsect2 id="regexp.reference.back-references"> + <title>Back references</title> + <para> Outside a character class, a backslash followed by a digit greater than 0 (and possibly further digits) is a back reference to a capturing subpattern earlier (i.e. to its left) in the pattern, provided there have been that many previous capturing left parentheses. - </para> - <para> + </para> + <para> However, if the decimal number following the backslash is less than 10, it is always taken as a back reference, and causes an error only if there are not that many capturing @@ -1245,8 +1158,8 @@ the reference for numbers less than 10. See the section entitled "Backslash" above for further details of the handling of digits following a backslash. - </para> - <para> + </para> + <para> A back reference matches whatever actually matched the capturing subpattern in the current subject string, rather than anything matching the subpattern itself. So the pattern @@ -1262,8 +1175,8 @@ matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capturing subpattern is matched caselessly. - </para> - <para> + </para> + <para> There may be more than one back reference to the same subpattern. If a subpattern has not actually been used in a particular match, then any back references to it always @@ -1278,8 +1191,8 @@ character, then some delimiter must be used to terminate the back reference. If the <link linkend="reference.pcre.pattern.modifiers">PCRE_EXTENDED</link> option is set, this can be whitespace. Otherwise an empty comment can be used. - </para> - <para> + </para> + <para> A back reference that occurs inside the parentheses to which it refers fails when the subpattern is first used, so, for example, (a\1) never matches. However, such references can @@ -1294,12 +1207,12 @@ that the first iteration does not need to match the back reference. This can be done using alternation, as in the example above, or by a quantifier with a minimum of zero. - </para> - </refsect2> + </para> + </refsect2> - <refsect2 id="regexp.reference.assertions"> - <title>Assertions</title> - <para> + <refsect2 id="regexp.reference.assertions"> + <title>Assertions</title> + <para> An assertion is a test on the characters following or preceding the current matching point that does not actually consume any characters. The simple assertions coded as \b, @@ -1307,8 +1220,8 @@ assertions are coded as subpatterns. There are two kinds: those that look ahead of the current position in the subject string, and those that look behind it. - </para> - <para> + </para> + <para> An assertion subpattern is matched in the normal way, except that it does not cause the current matching position to be changed. Lookahead assertions start with (?= for positive @@ -1331,8 +1244,8 @@ whatsoever, because the assertion (?!foo) is always &true; when the next three characters are "bar". A lookbehind assertion is needed to achieve this effect. - </para> - <para> + </para> + <para> Lookbehind assertions start with (?&lt;= for positive assertions and (?&lt;! for negative assertions. For example, @@ -1372,8 +1285,8 @@ once-only subpatterns can be particularly useful for matching at the ends of strings; an example is given at the end of the section on once-only subpatterns. - </para> - <para> + </para> + <para> Several assertions (of any sort) may occur in succession. For example, @@ -1389,15 +1302,15 @@ of which are not "999". For example, it doesn't match "123abcfoo". A pattern to do that is - <literal>(?&lt;=\d{3}...)(?&lt;!999)foo</literal> - </para> - <para> + <literal>(?&lt;=\d{3}...)(?&lt;!999)foo</literal> + </para> + <para> This time the first assertion looks at the preceding six characters, checking that the first three are digits, and then the second assertion checks that the preceding three characters are not "999". - </para> - <para> + </para> + <para> Assertions can be nested in any combination. For example, <literal>(?&lt;=(?&lt;!foo)bar)baz</literal> @@ -1409,8 +1322,8 @@ is another pattern which matches "foo" preceded by three digits and any three characters that are not "999". - </para> - <para> + </para> + <para> Assertion subpatterns are not capturing subpatterns, and may not be repeated, because it makes no sense to assert the same thing several times. If any kind of assertion contains @@ -1419,16 +1332,16 @@ pattern. However, substring capturing is carried out only for positive assertions, because it does not make sense for negative assertions. - </para> - <para> + </para> + <para> Assertions count towards the maximum of 200 parenthesized subpatterns. - </para> - </refsect2> + </para> + </refsect2> - <refsect2 id="regexp.reference.onlyonce"> - <title>Once-only subpatterns</title> - <para> + <refsect2 id="regexp.reference.onlyonce"> + <title>Once-only subpatterns</title> + <para> With both maximizing and minimizing repetition, failure of what follows normally causes the repeated item to be re-evaluated to see if a different number of repeats allows the @@ -1437,14 +1350,14 @@ to cause it fail earlier than it otherwise might, when the author of the pattern knows there is no point in carrying on. - </para> - <para> + </para> + <para> Consider, for example, the pattern \d+foo when applied to the subject line <literal>123456bar</literal> - </para> - <para> + </para> + <para> After matching all 6 digits and then failing to match "foo", the normal action of the matcher is to try again with only 5 digits matching the \d+ item, and then with 4, and so on, @@ -1456,32 +1369,32 @@ parenthesis, starting with (?&gt; as in this example: <literal>(?&gt;\d+)bar</literal> - </para> - <para> + </para> + <para> This kind of parenthesis "locks up" the part of the pattern it contains once it has matched, and a failure further into the pattern is prevented from backtracking into it. Backtracking past it to previous items, however, works as normal. - </para> - <para> + </para> + <para> An alternative description is that a subpattern of this type matches the string of characters that an identical standalone pattern would match, if anchored at the current point in the subject string. - </para> - <para> + </para> + <para> Once-only subpatterns are not capturing subpatterns. Simple cases such as the above example can be thought of as a maximizing repeat that must swallow everything it can. So, while both \d+ and \d+? are prepared to adjust the number of digits they match in order to make the rest of the pattern match, (?&gt;\d+) can only match an entire sequence of digits. - </para> - <para> + </para> + <para> This construction can of course contain arbitrarily complicated subpatterns, and it can be nested. - </para> - <para> + </para> + <para> Once-only subpatterns can be used in conjunction with look-behind assertions to specify efficient matching at the end of the subject string. Consider a simple pattern such as @@ -1509,8 +1422,8 @@ assertion does a single test on the last four characters. If it fails, the match fails immediately. For long strings, this approach makes a significant difference to the processing time. - </para> - <para> + </para> + <para> When a pattern contains an unlimited repeat inside a subpattern that can itself be repeated an unlimited number of times, the use of a once-only subpattern is the only way to @@ -1539,31 +1452,31 @@ <literal>((?>\D+)|&lt;\d+>)*[!?]</literal> sequences of non-digits cannot be broken, and failure happens quickly. - </para> - </refsect2> + </para> + </refsect2> - <refsect2 id="regexp.reference.conditional"> - <title>Conditional subpatterns</title> - <para> + <refsect2 id="regexp.reference.conditional"> + <title>Conditional subpatterns</title> + <para> It is possible to cause the matching process to obey a subpattern conditionally or to choose between two alternative subpatterns, depending on the result of an assertion, or whether a previous capturing subpattern matched or not. The two possible forms of conditional subpattern are - </para> + </para> - <literallayout> + <literallayout> (?(condition)yes-pattern) (?(condition)yes-pattern|no-pattern) - </literallayout> - <para> + </literallayout> + <para> If the condition is satisfied, the yes-pattern is used; otherwise the no-pattern (if present) is used. If there are more than two alternatives in the subpattern, a compile-time error occurs. - </para> - <para> - There are two kinds of condition. If the text between the + </para> + <para> + There are two kinds of condition. If the text between the parentheses consists of a sequence of digits, then the condition is satisfied if the capturing subpattern of that number has previously matched. Consider the following pattern, @@ -1572,8 +1485,8 @@ divide it into three parts for ease of discussion: <literal>( \( )? [^()]+ (?(1) \) )</literal> - </para> - <para> + </para> + <para> The first part matches an optional opening parenthesis, and if that character is present, sets it as the first captured substring. The second part matches one or more characters @@ -1586,25 +1499,25 @@ subpattern matches nothing. In other words, this pattern matches a sequence of non-parentheses, optionally enclosed in parentheses. - </para> - <para> + </para> + <para> If the condition is the string <literal>(R)</literal>, it is satisfied if a recursive call to the pattern or subpattern has been made. At "top level", the condition is false. - </para> - <para> + </para> + <para> If the condition is not a sequence of digits or (R), it must be an assertion. This may be a positive or negative lookahead or lookbehind assertion. Consider this pattern, again containing non-significant white space, and with the two alternatives on the second line: - </para> + </para> - <literallayout> + <literallayout> (?(?=[^a-z]*[a-z]) \d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} ) - </literallayout> - <para> + </literallayout> + <para> The condition is a positive lookahead assertion that matches an optional sequence of non-letters followed by a letter. In other words, it tests for the presence of at least one @@ -1613,27 +1526,23 @@ matched against the second. This pattern matches strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are letters and dd are digits. - </para> - </refsect2> + </para> + </refsect2> - <refsect2 id="regexp.reference.comments"> - <title>Comments</title> - <para> - The sequence (?# marks the start of a comment which - continues up to the next closing parenthesis. Nested - parentheses are not permitted. The characters that make up a - comment play no part in the pattern matching at all. - </para> - <para> - If the <link linkend="reference.pcre.pattern.modifiers">PCRE_EXTENDED</link> option is set, an unescaped # character - outside a character class introduces a comment that - continues up to the next newline character in the pattern. - </para> - </refsect2> + <refsect2 id="regexp.reference.comments"> + <title>×¢ÊÍ</title> + <para> + ÐòÁÐ (?# ±ê¼ÇÁË×¢Ê͵ĿªÍ·Ö±µ½ÏÂÒ»¸öÓÒÀ¨ºÅΪֹ¡£²»ÔÊÐíǶÌ××¢ÊÍ¡£×¢ÊÍÔÚģʽƥÅäÖÐÍêȫûÓÐ×÷Óᣠ+ </para> + <para> + Èç¹ûÉ趨ÁË <link linkend="reference.pcre.pattern.modifiers">PCRE_EXTENDED</link> + Ñ¡ÏÔò²»ÔÚ×Ö·ûÀàÖм䲢ÇÒδתÒåµÄ # ×Ö·û±ê¼ÇÁË×¢Ê͵ĿªÍ·£¬Ö±µ½Ä£Ê½ÖеÄÏÂÒ»¸ö»»Ðзû½áÊø¡£ + </para> + </refsect2> - <refsect2 id="regexp.reference.recursive"> - <title>Recursive patterns</title> - <para> + <refsect2 id="regexp.reference.recursive"> + <title>Recursive patterns</title> + <para> Consider the problem of matching a string in parentheses, allowing for unlimited nested parentheses. Without the use of recursion, the best that can be done is to use a pattern @@ -1648,15 +1557,15 @@ ignored): <literal>\( ( (?>[^()]+) | (?R) )* \)</literal> - </para> - <para> + </para> + <para> First it matches an opening parenthesis. Then it matches any number of substrings which can either be a sequence of non-parentheses, or a recursive match of the pattern itself (i.e. a correctly parenthesized substring). Finally there is a closing parenthesis. - </para> - <para> + </para> + <para> This particular example pattern contains nested unlimited repeats, and so the use of a once-only subpattern for matching strings of non-parentheses is important when applying @@ -1670,8 +1579,8 @@ indeed because there are so many different ways the + and * repeats can carve up the subject, and all have to be tested before failure can be reported. - </para> - <para> + </para> + <para> The values set for any capturing subpatterns are those from the outermost level of the recursion at which the subpattern value is set. If the pattern above is matched against @@ -1692,14 +1601,14 @@ saves data for the first 15 capturing parentheses only, as there is no way to give an out-of-memory error from within a recursion. - </para> + </para> - <para> + <para> Since PHP 4.3.3, <literal>(?1)</literal>, <literal>(?2)</literal> and so on can be used for recursive subpatterns too. It is also possible to use named subpatterns: <literal>(?P>foo)</literal>. - </para> - <para> + </para> + <para> If the syntax for a recursive subpattern reference (either by number or by name) is used outside the parentheses to which it refers, it operates like a subroutine in a programming language. An earlier example @@ -1711,13 +1620,12 @@ is used, it does match "sense and responsibility" as well as the other two strings. Such references must, however, follow the subpattern to which they refer. - </para> - - </refsect2> + </para> + </refsect2> - <refsect2 id="regexp.reference.performances"> - <title>Performances</title> - <para> + <refsect2 id="regexp.reference.performances"> + <title>Performances</title> + <para> Certain items that may appear in patterns are more efficient than others. It is more efficient to use a character class like [aeiou] than a set of alternatives such as (a|e|i|o|u). @@ -1725,8 +1633,8 @@ required behaviour is usually the most efficient. Jeffrey Friedl's book contains a lot of discussion about optimizing regular expressions for efficient performance. - </para> - <para> + </para> + <para> When a pattern begins with .* and the <link linkend="reference.pcre.pattern.modifiers">PCRE_DOTALL</link> option is set, the pattern is implicitly anchored by PCRE, since it can match only at the start of a subject string. However, if @@ -1742,22 +1650,22 @@ a newline character) with the first captured substring being "and". In order to do this, PCRE has to retry the match starting after every newline in the subject. - </para> - <para> + </para> + <para> If you are using such a pattern with subject strings that do not contain newlines, the best performance is obtained by setting <link linkend="reference.pcre.pattern.modifiers">PCRE_DOTALL</link>, or starting the pattern with ^.* to indicate explicit anchoring. That saves PCRE from having to scan along the subject looking for a newline to restart at. - </para> - <para> + </para> + <para> Beware of patterns that contain nested indefinite repeats. These can take a long time to run when applied to a string that does not match. Consider the pattern fragment <literal>(a+)*</literal> - </para> - <para> + </para> + <para> This can match "aaaa" in 33 different ways, and this number increases very rapidly as the string gets longer. (The * repeat can match 0, 1, 2, 3, or 4 times, and for each of @@ -1766,8 +1674,8 @@ that the entire match is going to fail, PCRE has in principle to try every possible variation, and this can take an extremely long time. - </para> - <para> + </para> + <para> An optimization catches some of the more simple cases such as @@ -1786,10 +1694,10 @@ instantly when applied to a whole line of "a" characters, whereas the latter takes an appreciable time with strings longer than about 20 characters. - </para> - </refsect2> - </refsect1> - </refentry> + </para> + </refsect2> + </refsect1> +</refentry> <!-- Keep this comment at the end of the file Local variables:
« previous php.doc.zh (#2765) next »