You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -882,6 +883,30 @@ The `Str::replaceLast` method replaces the last occurrence of a given value in a
882
883
883
884
// the quick brown fox jumps over a lazy dog
884
885
886
+
<aname="method-str-replace-matches"></a>
887
+
#### `Str::replaceMatches()` {.collection-method}
888
+
889
+
The `Str::replaceMatches` method replaces all portions of a string matching a pattern with the given replacement string:
890
+
891
+
use Illuminate\Support\Str;
892
+
893
+
$replaced = Str::replaceMatches(
894
+
pattern: '/[^A-Za-z0-9]++/',
895
+
replace: '',
896
+
subject: '(+1) 501-555-1000'
897
+
)
898
+
899
+
// '15015551000'
900
+
901
+
The `replaceMatches` method also accepts a closure that will be invoked with each portion of the string matching the given pattern, allowing you to perform the replacement logic within the closure and return the replaced value:
902
+
903
+
use Illuminate\Support\Str;
904
+
905
+
$replaced = Str::replaceMatches('/\d/', function (array $matches) {
0 commit comments