I already have a routing method that matches this pattern:
/hello/:name
that set name to be a dynamic path, I want to know how to make it:
/hello/{name}
with the same regex. How to add optional trailing slash to it, like this?
/hello/:name(/)
or
/hello/{name}(/)
This is the regex I use for /hello/:name
@^/hello/([a-zA-Z0-9\-\_]+)$@D
The regex is auto generated from PHP class
private function getRegex($pattern){
$patternAsRegex = "@^" . preg_replace('/\\\:[a-zA-Z0-9\_\-]+/', '([a-zA-Z0-9\-\_]+)', preg_quote($pattern)) . "$@D";
return $patternAsRegex;
}
If the route is /hello/:name(/) I want it to make the match with optional thing else continue normal
Aucun commentaire:
Enregistrer un commentaire