<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.filter.set.pregreplace">
    <title>PregReplace</title>

    <para>
        <classname>Zend_Filter_PregReplace</classname> performs a search using regular expressions
        and replaces all found elements.
    </para>

    <sect3 id="zend.filter.set.pregreplace.options">
        <title>Supported options for Zend_Filter_PregReplace</title>

        <para>
            The following options are supported for <classname>Zend_Filter_PregReplace</classname>:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <emphasis><property>match</property></emphasis>: The pattern which will be
                    searched for.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis><property>replace</property></emphasis>: The string which is used as
                    replacement for the matches.
                </para>
            </listitem>
        </itemizedlist>
    </sect3>

    <sect3 id="zend.filter.set.pregreplace.basic">
        <title>Basic usage</title>

        <para>
            To use this filter properly you must give two options:
        </para>

        <para>
            The option <property>match</property> has to be given to set the pattern which will be
            searched for. It can be a string for a single pattern, or an array of strings for
            multiple pattern.
        </para>

        <para>
            To set the pattern which will be used as replacement the option
            <property>replace</property> has to be used. It can be a string for a single pattern, or
            an array of strings for multiple pattern.
        </para>

        <programlisting language="php"><![CDATA[
$filter = new Zend_Filter_PregReplace(array('match' => '/bob/',
                                            'replace' => 'john'));
$input  = 'Hy bob!';

$filter->filter($input);
// returns 'Hy john!'
]]></programlisting>

        <para>
            You can use <methodname>getMatchPattern()</methodname> and
            <methodname>setMatchPattern()</methodname> to set the matching pattern afterwards. To
            set the replacement pattern you can use <methodname>getReplacement()</methodname> and
            <methodname>setReplacement()</methodname>.
        </para>

        <programlisting language="php"><![CDATA[
$filter = new Zend_Filter_PregReplace();
$filter->setMatchPattern(array('bob', 'Hy'))
       ->setReplacement(array('john', 'Bye'));
$input  = 'Hy bob!";

$filter->filter($input);
// returns 'Bye john!'
]]></programlisting>

        <para>
            For a more complex usage take a look into <acronym>PHP</acronym>'s <ulink
                url="http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php">PCRE
                Pattern Chapter</ulink>.
        </para>
    </sect3>
</sect2>
