src/Gobie/Regex/Wrappers/Mb/MbRegex.php
public static function filter($pattern, $replacement, $subject, $option = '')
    {
        static::setUp($pattern);

        $replaceMap = self::prepareReplaceMap($pattern, $replacement);

        $result = array();
        foreach ((array) $subject as $key => $subjectPart) {
            foreach ($replaceMap as $item) {
                list($pattern, $replacement) = $item;

                \mb_ereg_search_init($subjectPart, $pattern, $option);
                if (!\mb_ereg_search()) {
                    continue;
                }

                $subjectPart  = self::execReplace($pattern, $replacement, $subjectPart, $option);
                $result[$key] = $subjectPart;
            }
        }

        static::tearDown();

        return $result;
    }
public static function filter($pattern, $replacement, $subject, $option = '')
    {
        static::setUp($pattern);

        $replaceMap = self::prepareReplaceMap($pattern, $replacement);

        $result = array();
        foreach ((array) $subject as $key => $subjectPart) {
            foreach ($replaceMap as $item) {
                list($pattern, $replacement) = $item;

                \mb_ereg_search_init($subjectPart, $pattern, $option);
                if (!\mb_ereg_search()) {
                    continue;
                }

                $subjectPart  = self::execReplace($pattern, $replacement, $subjectPart, $option);
                $result[$key] = $subjectPart;
            }
        }

        static::tearDown();

        return $result;
    }
Regular expression filter and return only replaced.

Warning, take care that callback does not trigger any errors or the PHP will just die with some weird exit code.

@param string|string[]         $pattern     Pattern or array of patterns
@param callable|string|mixed[] $replacement Replacement (string or callback) or array of replacements
@param string|string[]         $subject     Subject or array of subjects
@param string                  $option      Option
@return string[] Array of filtered subjects
@throws MbRegexException When compilation error occurs
@link http://php.net/function.mb-ereg-search.php
@link http://php.net/function.mb-ereg-replace.php
@link http://php.net/function.mb-ereg-replace-callback.php