0

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.

Zamrony P. Juhara
  • 5,222
  • 2
  • 24
  • 40

1 Answers1

0

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.

Benni
  • 1,023
  • 11
  • 15