About matching with regular expressions
riku22 opened this issue · comments
Hello.
I created a routing like the one below, but it doesn't work.
What should I do now?
SimpleRouter::get('/api/test/v{api_version}/{name}', function($api_version, $name){
var_dump($api_version);
var_dump($name);
})
->where([
'api_version' => '[0-9]+',
'name' => '[a-zA-Z]+',
]);
I'm expecting it to work with a URL like /api/test/v1/abc
, but I get a 404 error.
I would appreciate any advice.
Did u try to remove the v in the api_version?
Hello.
In the end, I decided to remove the leading "v" in the function and use it.
SimpleRouter::get('/api/test/{api_version}/{name}', function($api_version, $name){
$api_version = preg_replace('/^v/i', '', $api_version);
var_dump($api_version);
var_dump($name);
})
->where([
'api_version' => 'v[0-9]+',
'name' => '[a-zA-Z]+',
]);
Thank you.