Skip to content

Commit

Permalink
[10.x] Add replaceMatches to Str class (#48727)
Browse files Browse the repository at this point in the history
* add replaceMatches to Str class

* Update Str.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
hosmelq and taylorotwell authored Oct 16, 2023
1 parent cdcb9ca commit 1bae4cd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 1bae4cd

Please sign in to comment.