svn: /phpdoc/en/trunk/reference/pcre/ pattern.syntax.xml

From: Date: Fri, 07 May 2010 20:28:05 +0000
Subject: svn: /phpdoc/en/trunk/reference/pcre/ pattern.syntax.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-6604@lists.php.net to get a copy of this message
salathe Fri, 07 May 2010 20:28:05 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=299124 Log: added pcre \g description (patch from Peter O'Callaghan) Changed paths: U phpdoc/en/trunk/reference/pcre/pattern.syntax.xml Modified: phpdoc/en/trunk/reference/pcre/pattern.syntax.xml =================================================================== --- phpdoc/en/trunk/reference/pcre/pattern.syntax.xml 2010-05-07 19:37:58 UTC (rev 299123) +++ phpdoc/en/trunk/reference/pcre/pattern.syntax.xml 2010-05-07 20:28:05 UTC (rev 299124) @@ -1282,7 +1282,8 @@ As of PHP 4.3.3, it is possible to name a subpattern using the syntax <literal>(?P&lt;name&gt;pattern)</literal>. This subpattern will then be indexed in the matches array by its normal numeric position and - also by name. + also by name. PHP 5.2.2 introduced two alternative syntaxes + <literal>(?&lt;name&gt;pattern)</literal> and <literal>(?'name'pattern)</literal>. </para> </section> @@ -1537,12 +1538,32 @@ reference. This can be done using alternation, as in the example above, or by a quantifier with a minimum of zero. </para> - <para> + As of PHP 5.2.2, the <literal>\g</literal> escape sequence can be + used for absolute and relative referencing of subpatterns. + This escape sequence must be followed by an unsigned number or a negative + number, optionally enclosed in braces. The sequences <literal>\1</literal>, + <literal>\g1</literal> and <literal>\g{1}</literal> are synonymous + with one another. The use of this pattern with an unsigned number can + help remove the ambiguity inherent when using digits following a + backslash. The sequence helps to distinguish back references from octal + characters and also makes it easier to have a back reference followed + by a literal number, e.g. <literal>\g{2}1</literal>. + </para> + <para> + The use of the <literal>\g</literal> sequence with a negative number + signifies a relative reference. For example, <literal>(foo)(bar)\g{-1}</literal> + would match the sequence "foobarbar" and <literal>(foo)(bar)\g{-2}</literal> + matches "foobarfoo". This can be useful in long patterns as an alternative + to keeping track of the number of subpatterns in order to reference + a specific previous subpattern. + </para> + <para> Back references to the named subpatterns can be achieved by - <literal>(?P=name)</literal> or, since PHP 5.2.4, also by - <literal>\k&lt;name&gt;</literal>, <literal>\k'name'</literal>, - <literal>\k{name}</literal> or <literal>\g{name}</literal>. + <literal>(?P=name)</literal> or, since PHP 5.2.2, also by + <literal>\k&lt;name&gt;</literal> or <literal>\k'name'</literal>. + Additionally PHP 5.2.4 added support for <literal>\k{name}</literal> + and <literal>\g{name}</literal>. </para> </section>

« previous php.doc.cvs (#6604) next »