simplified regex for route creation

This commit is contained in:
tracer 2022-10-24 18:56:30 +02:00
parent 7e19efd420
commit d2cdcdded4

View File

@ -44,7 +44,7 @@ class Router
$parameters = $matches[0];
// create regex for route:
$regex = preg_replace(pattern: '/{(?<=).+?(?=)}/', replacement: '([a-zA-Z0-9]*)', subject: $route);
$regex = preg_replace(pattern: '/{.+?}/', replacement: '([a-zA-Z0-9]*)', subject: $route);
$regex = '/^' . str_replace(search: "/", replace: '\\/', subject: $regex) . '$/i';
$route = new Route(name: $name, route: $route, regEx: $regex, parameters: $parameters, callback: $callback);