diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index c1cc95f2fbc9..7bd8af8ac3a8 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -1141,6 +1141,24 @@ public static function replaceEnd($search, $replace, $subject) return $subject; } + /** + * Replace the patterns matching the given regular expression. + * + * @param string $pattern + * @param \Closure|string $replace + * @param array|string $subject + * @param int $limit + * @return string|string[]|null + */ + public function replaceMatches($pattern, $replace, $subject, $limit = -1) + { + if ($replace instanceof Closure) { + return preg_replace_callback($pattern, $replace, $subject, $limit); + } + + return preg_replace($pattern, $replace, $subject, $limit); + } + /** * Remove any occurrence of the given string in the subject. *