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

match()->first() #10

Closed
danon opened this issue Sep 18, 2018 · 1 comment
Closed

match()->first() #10

danon opened this issue Sep 18, 2018 · 1 comment

Comments

@danon
Copy link
Member

danon commented Sep 18, 2018

Example: (list of people, some with ages)

Clark, Brian 23, Olivia, Jane 24, Marcin 26

New API:

  • Returns a group from the first match or throws exception
    pattern('[a-z]+(?: (?<age>\d+))?')->match($s)->group('age')->first();
    Throw GroupNotMatchedException if subject matched, but group wasn't.
@danon
Copy link
Member Author

danon commented Sep 24, 2018

Right now, the only way to conrol both match and might be group:

pattern('xd')->match($subject)
    ->forFirst(function (Match $match) {
        $match->group('age')->orElse();    // subject matched, group not
        $match->group('age')->orReturn();
        $match->group('age')->orThrow();
    })
  ->orDefault('Nothing');

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

No branches or pull requests

1 participant