Added section that outlines notable differences between POSIX regex and PCRE regex.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@296975 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Daniel Egeberg 2010-03-28 15:02:41 +00:00
parent 81d42a8080
commit 9726e9e4fc
3 changed files with 116 additions and 1 deletions

View file

@ -10,7 +10,8 @@ number generator is seeded automatically.</entry></row>'>
<!ENTITY note.regex.deprecated '<note xmlns="http://docbook.org/ns/docbook"><para>As of PHP 5.3.0, the
regex extension is deprecated in favor of the
<link linkend="book.pcre">PCRE extension</link>. Calling this function
will issue an <constant>E_DEPRECATED</constant> notice.</para></note>'>
will issue an <constant>E_DEPRECATED</constant> notice. See <link linkend="reference.pcre.pattern.posix">the list of
differences</link> for help on converting to PCRE.</para></note>'>
<!ENTITY note.bin-safe '<note xmlns="http://docbook.org/ns/docbook"><simpara>This function is
binary-safe.</simpara></note>'>

View file

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<article xml:id="reference.pcre.pattern.posix" xmlns="http://docbook.org/ns/docbook">
<title>Differences from POSIX regex</title>
<para>
As of PHP 5.3.0, the <link linkend="book.regex">POSIX Regex</link> extension
is deprecated. There are a number of differences between POSIX regex and
PCRE regex. This page lists the most notable ones that are necessary to
know when converting to PCRE.
</para>
<para>
<orderedlist>
<listitem>
<simpara>
The PCRE functions require that the pattern is enclosed by <link
linkend="regexp.reference.delimiters">delimiters</link>.
</simpara>
</listitem>
<listitem>
<simpara>
Unlike POSIX, the PCRE extension does not have dedicated functions for
case-insensitive matching. Instead, this is supported using the /i <link
linkend="reference.pcre.pattern.modifiers">pattern modifier</link>. Other
pattern modifiers are also available for changing the matching strategy.
</simpara>
</listitem>
<listitem>
<simpara>
The POSIX functions find the longest of the leftmost match, but PCRE
stops on the first valid match. If the string doesn't match at all it
makes no difference, but if it matches it may have dramatic effects on
both the resulting match and the matching speed.
</simpara>
<simpara>
To illustrate this difference, consider the following example from
"Mastering Regular Expressions" by Jeffrey Friedl. Using the pattern
<literal>one(self)?(selfsufficient)?</literal> on the string
<literal>oneselfsufficient</literal> with PCRE will result in matching
<literal>oneself</literal>, but using POSIX the result will be the full
string <literal>oneselfsufficient</literal>. Both (sub)strings match the
original string, but POSIX requires that the longest be the result.
</simpara>
</listitem>
</orderedlist>
</para>
<para>
<table>
<title>Function replacements</title>
<tgroup cols="2">
<thead>
<row>
<entry>POSIX</entry>
<entry>PCRE</entry>
</row>
</thead>
<tbody>
<row>
<entry><function>ereg_replace</function></entry>
<entry><function>preg_replace</function></entry>
</row>
<row>
<entry><function>ereg</function></entry>
<entry><function>preg_match</function></entry>
</row>
<row>
<entry><function>eregi_repalce</function></entry>
<entry><function>preg_replace</function></entry>
</row>
<row>
<entry><function>eregi</function></entry>
<entry><function>preg_match</function></entry>
</row>
<row>
<entry><function>split</function></entry>
<entry><function>preg_split</function></entry>
</row>
<row>
<entry><function>spliti</function></entry>
<entry><function>preg_split</function></entry>
</row>
<row>
<entry><function>sql_regcase</function></entry>
<entry><emphasis>No equivalent</emphasis></entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</article>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -6,6 +6,7 @@
&reference.pcre.pattern.modifiers;
&reference.pcre.pattern.differences;
&reference.pcre.pattern.posix;
&reference.pcre.pattern.syntax;
</part>