Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Adds match and matchAll to Str #37642

Merged
merged 2 commits into from
Jun 10, 2021
Merged

[8.x] Adds match and matchAll to Str #37642

merged 2 commits into from
Jun 10, 2021

Conversation

lukeraymonddowning
Copy link
Contributor

Hi all,

Previously, match and matchAll were exclusively part of the Stringable class. You couldn't use those methods with the standard Str helper.

Str::of('xyz')->match('/(xyz)/'); // works
Str::match('/(xyz)/'); // does not work

This PR moves the logic of match and matchAll into two methods on the Str helper class, rather than the Stringable class, so that it can be used in both instances.

Thanks as always for you time and hard work maintaining such a great framework 😀

Luke

@foremtehan
Copy link
Contributor

foremtehan commented Jun 10, 2021

Another things with match and matchAll it only return group 1 or 0, So you cannot do this :

return collect($matches[1] ?? $matches[0]);

preg_match('~regex~', $input, $m); //having 4 groups for example

$arranged = array_map(function ($a, $b, $c, $d) {
    return [
        ...
    ];
}, $m[1], $m[2], $m[3], $m[4]);

#35509

Wish we could have a solution for this because i really works a lot with regex.

@taylorotwell taylorotwell merged commit 38d44bb into laravel:8.x Jun 10, 2021
@lukeraymonddowning lukeraymonddowning deleted the stringable-matches branch June 10, 2021 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants