slim 3 regex route

1k views Asked by At

I'm trying to match a route that has the keywords -episode or -movie.

Such as /steins-gate-episode-1 or /pokemon-movie-10

I tried doing this:

$app->get('/{slug:episode|movie}', \App\Controller\EpisodeController::class . ':getBySlug');

But it isn't matching.

Any help would be appreciated. I am completely new to this btw.

1

There are 1 answers

0
Benni On

Your regular expression matches only the exact strings "episode" and "movie". If you want to check if the URL contains the substrings, you can use this:

$app->get('/{slug:.*episode.*|.*movie.*}', function ($request, $response, $args) {
    echo $args['slug'];
});

.* means "any number of any character" . Sure are there more advanced regexp patterns but that will do what you need.