src/Gobie/Regex/Wrappers/Mb/MbRegex.php
public static function replace($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;

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

        static::tearDown();

        return (\is_array($subject) ? $result : \reset($result)) ? : $subject;
    }
public static function replace($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;

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

        static::tearDown();

        return (\is_array($subject) ? $result : \reset($result)) ? : $subject;
    }
Regular expression replace and return 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|string[] Replaced subject or array of subjects
@throws MbRegexException When compilation error occurs
@link http://php.net/function.mb-ereg-replace.php
@link http://php.net/function.mb-ereg-replace-callback.php