mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
added pcre \g description (patch from Peter O'Callaghan)
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@299124 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
5106f79967
commit
1ad390c81a
1 changed files with 26 additions and 5 deletions
|
@ -1282,7 +1282,8 @@
|
|||
As of PHP 4.3.3, it is possible to name a subpattern using the syntax
|
||||
<literal>(?P<name>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>(?<name>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<name></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<name></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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue