Clarify some details of using bracket-style delimiters in regular expression patterns

Patch suggested by Brandon Kelly (brandon@pixelandtonic.com)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@334410 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Chris Wright 2014-07-29 12:46:16 +00:00
parent 092ad46255
commit d28c33adb9

View file

@ -44,20 +44,7 @@
#^[^0-9]$#
+php+
%[a-zA-Z0-9_-]%
]]>
</programlisting>
</informalexample>
</para>
<para>
In addition to the aforementioned delimiters, it is also possible to use
bracket style delimiters where the opening and closing brackets are the
starting and ending delimiter, respectively.
<informalexample>
<programlisting>
<![CDATA[
{this is a pattern}
(foobar)
<\d+>
{\w[\w0-9]*}
]]>
</programlisting>
</informalexample>
@ -79,6 +66,26 @@
for injection into a pattern and its optional second parameter may be used
to specify the delimiter to be escaped.
</para>
<para>
In addition to the aforementioned delimiters, it is also possible to use
bracket style delimiters where the opening and closing brackets are the
starting and ending delimiter, respectively. <literal>()</literal>,
<literal>{}</literal>, <literal>[]</literal> and <literal>&lt;&gt;</literal>
are all valid bracket style delimiter pairs.
<informalexample>
<programlisting>
<![CDATA[
(this [is] a (pattern))
{this [is] a (pattern)}
[this [is] a (pattern)]
<this [is] a (pattern)>
]]>
</programlisting>
</informalexample>
Bracket style delimiters do not need to be escaped when they are used as meta
characters within the pattern, but as with other delimiters they must be
escaped when they are used as literal characters.
</para>
<para>
You may add <link linkend="reference.pcre.pattern.modifiers">pattern
modifiers</link> after the ending delimiter. The following is an example